ganeswidgets/tsrc/unit/unittest_ganeswidgets.cpp
changeset 1 e48454f237ca
parent 0 89c329efa980
child 3 c863538fcbb6
equal deleted inserted replaced
0:89c329efa980 1:e48454f237ca
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
    19 #include <QMetaType>
    19 #include <QMetaType>
    20 #include <QModelIndex>
    20 #include <QModelIndex>
    21 #include "hbautotest.h"
    21 #include "hbautotest.h"
    22 #include <hbapplication.h>
    22 #include <hbapplication.h>
       
    23 #include <hblabel.h>
    23 #include <hbmainwindow.h>
    24 #include <hbmainwindow.h>
    24 #include <hbscrollbar>
    25 #include <hbscrollbar>
       
    26 #include <hbview>
    25 #include <hgwidgets/hgwidgets.h>
    27 #include <hgwidgets/hgwidgets.h>
    26 #include <hgwidgets/hggrid.h>
    28 #include <hgwidgets/hggrid.h>
    27 #include <hgwidgets/hgmediawall.h>
    29 #include <hgwidgets/hgmediawall.h>
    28 
    30 
    29 Q_DECLARE_METATYPE(QItemSelection)
    31 Q_DECLARE_METATYPE(QItemSelection)
    37 static const QPointF grid_portrait_pos5(280, 120);
    39 static const QPointF grid_portrait_pos5(280, 120);
    38 static const QPointF grid_portrait_pos6(70, 200);
    40 static const QPointF grid_portrait_pos6(70, 200);
    39 static const QPointF grid_portrait_pos7(180, 200);
    41 static const QPointF grid_portrait_pos7(180, 200);
    40 static const QPointF grid_portrait_pos8(280, 200);
    42 static const QPointF grid_portrait_pos8(280, 200);
    41 
    43 
       
    44 // These work with 360x640 resolution
       
    45 static const QPointF expected_label_pos_above_alone(180, 144);
       
    46 static const QPointF expected_label_pos_above_top(180, 132);
       
    47 static const QPointF expected_label_pos_above_bottom(180, 163);
       
    48 static const QPointF expected_label_pos_below_alone(180, 324);
       
    49 static const QPointF expected_label_pos_below_top(180, 312);
       
    50 static const QPointF expected_label_pos_below_bottom(180, 342);
       
    51 
       
    52 static const int default_delay(1500);
       
    53 
    42 class TestGanesWidgets : public QObject
    54 class TestGanesWidgets : public QObject
    43 {
    55 {
    44     Q_OBJECT
    56     Q_OBJECT
    45 
    57 
    46 public:
    58 public:
    53     void cleanupTestCase();
    65     void cleanupTestCase();
    54     void init();
    66     void init();
    55     void cleanup();
    67     void cleanup();
    56 
    68 
    57 private slots:
    69 private slots:
       
    70     void test_setModel();
    58     void test_panGridLandscape();
    71     void test_panGridLandscape();
    59     void test_panGridPortrait();
    72     void test_panGridPortrait();
    60     void test_panCoverFlowLandscape();
    73     void test_panCoverFlowLandscape();
    61     void test_panCoverFlowPortrait();
    74     void test_panCoverFlowPortrait();
    62     void test_scrollbarGridLandscape();
    75     void test_scrollbarGridLandscape();
    73     void test_selectionModel();
    86     void test_selectionModel();
    74     void test_scrollTo();
    87     void test_scrollTo();
    75     void test_addItemsCoverFlow();
    88     void test_addItemsCoverFlow();
    76     void test_removeItemsCoverFlow();
    89     void test_removeItemsCoverFlow();
    77     void test_moveItemsCoverFlow();
    90     void test_moveItemsCoverFlow();
       
    91     void test_labelPositionsCoverFlow();
       
    92     void test_labelFontSpecsCoverFlow();
       
    93     void test_resetModelCoverFlow();
       
    94     void test_resetModelGrid();
    78 
    95 
    79 private:
    96 private:
    80 
    97 
    81     void pan( Qt::Orientation, TBool begin );
    98     void pan( Qt::Orientation, TBool begin );
       
    99     bool checkLabelAt(HbMainWindow *window, const QPointF &pos, const QString &expectedText);
       
   100     HbLabel *findLabelAt(QGraphicsItem *parent, const QPointF &pos);
    82 
   101 
    83 private:
   102 private:
    84 
   103 
    85     HbMainWindow* mWindow;
   104     HbMainWindow* mWindow;
    86     HgWidget* mWidget;
   105     HgWidget* mWidget;
       
   106     HgMediawall* mMediawall;
    87 
   107 
    88 };
   108 };
    89 
   109 
    90 class TestModel : public QAbstractListModel
   110 class TestModel : public QAbstractListModel
    91 {
   111 {
   103     void appendItem();
   123     void appendItem();
   104     void insertItems(int index, int count=1);
   124     void insertItems(int index, int count=1);
   105     void removeItems(int index, int count=1);
   125     void removeItems(int index, int count=1);
   106     void moveItems(int from, int to, int count=1);
   126     void moveItems(int from, int to, int count=1);
   107     void changeItem(int index);
   127     void changeItem(int index);
   108     void reset();
   128     void reset(int newItemCount=0);
   109 
   129     
   110     QImage mImage;
   130     QImage mImage;
   111     QStringList mItems;
   131     QStringList mItems;
   112     bool mValidData;
   132     bool mValidData;
   113 
   133 
   114     QList<QModelIndex> *mRequestedIndexes;
   134     QList<QModelIndex> *mRequestedIndexes;
   127 }
   147 }
   128 
   148 
   129 void TestModel::generateItems(int count)
   149 void TestModel::generateItems(int count)
   130 {
   150 {
   131     for (int i=0; i<count; i++) {
   151     for (int i=0; i<count; i++) {
   132         mItems.append(QString("Item %0").arg(i));
   152         mItems.append(QString("Item ").append(i));
   133     }
   153     }
   134 }
   154 }
   135 
   155 
   136 void TestModel::appendItem()
   156 void TestModel::appendItem()
   137 {
   157 {
   141 void TestModel::insertItems(int index, int count)
   161 void TestModel::insertItems(int index, int count)
   142 {
   162 {
   143     beginInsertRows(QModelIndex(), index, index+count-1); // Inclusive
   163     beginInsertRows(QModelIndex(), index, index+count-1); // Inclusive
   144     int end = index+count;
   164     int end = index+count;
   145     for ( ;index<end; index++) {
   165     for ( ;index<end; index++) {
   146         mItems.insert(index, QString("Item %0").arg(mItems.count()));
   166         mItems.insert(index, QString("Item ").append(mItems.count()));
   147     }
   167     }
   148     endInsertRows();
   168     endInsertRows();
   149 }
   169 }
   150 
   170 
   151 void TestModel::removeItems(int index, int count)
   171 void TestModel::removeItems(int index, int count)
   169     else {
   189     else {
   170         qDebug() << "Cannot move" << from << "-" << from+count-1 << "to" << to;
   190         qDebug() << "Cannot move" << from << "-" << from+count-1 << "to" << to;
   171     }
   191     }
   172 }
   192 }
   173 
   193 
   174 void TestModel::reset()
   194 void TestModel::reset(int newItemCount)
   175 {
   195 {
   176     beginResetModel();
   196     beginResetModel();
   177     mItems.clear();
   197     mItems.clear();
       
   198     if (newItemCount > 0) {
       
   199         generateItems(newItemCount);
       
   200     }
   178     endResetModel();
   201     endResetModel();
   179 }
   202 }
   180 
       
   181 
   203 
   182 void TestModel::changeItem(int index)
   204 void TestModel::changeItem(int index)
   183 {
   205 {
   184     if ( index >= 0 && index < mItems.count() ) {
   206     if ( index >= 0 && index < mItems.count() ) {
   185         QModelIndex modelIndex = QAbstractItemModel::createIndex(index, 0);
   207         QModelIndex modelIndex = QAbstractItemModel::createIndex(index, 0);
   187     }
   209     }
   188 }
   210 }
   189 
   211 
   190 int TestModel::rowCount(const QModelIndex &parent) const
   212 int TestModel::rowCount(const QModelIndex &parent) const
   191 {
   213 {
       
   214     Q_UNUSED(parent);
       
   215 
   192     return mItems.count();
   216     return mItems.count();
   193 }
   217 }
   194 
   218 
   195 QVariant TestModel::data(const QModelIndex &index, int role) const
   219 QVariant TestModel::data(const QModelIndex &index, int role) const
   196 {
   220 {
   203 
   227 
   204     switch ( role )
   228     switch ( role )
   205         {
   229         {
   206         case Qt::DisplayRole:
   230         case Qt::DisplayRole:
   207             {
   231             {
   208             QStringList texts;
   232             QStringList list;
   209             QString text("Primary %0");
   233             list << QString("Primary %1").arg(row);
   210             text.arg(row);
   234             list << QString("Secondary %1").arg(row);
   211             texts << text;
   235             returnValue = list;
   212             text = "Secondary %0";
       
   213             text.arg(row);
       
   214             texts << text;
       
   215             returnValue = texts;
       
   216             break;
   236             break;
   217             }
   237             }
   218         case Qt::DecorationRole:
   238         case Qt::DecorationRole:
   219             {
   239             {
   220             returnValue = mImage;
   240             returnValue = mImage;
   282     HbAutoTest::mousePress( (HbAutoTestMainWindow*)mWindow, mWidget, start, -1 );
   302     HbAutoTest::mousePress( (HbAutoTestMainWindow*)mWindow, mWidget, start, -1 );
   283     HbAutoTest::mouseMove( (HbAutoTestMainWindow*)mWindow, mWidget, end, -1 );
   303     HbAutoTest::mouseMove( (HbAutoTestMainWindow*)mWindow, mWidget, end, -1 );
   284     HbAutoTest::mouseRelease( (HbAutoTestMainWindow*)mWindow, mWidget, end, 100 );
   304     HbAutoTest::mouseRelease( (HbAutoTestMainWindow*)mWindow, mWidget, end, 100 );
   285 }
   305 }
   286 
   306 
       
   307 void TestGanesWidgets::test_setModel()
       
   308 {
       
   309     mWindow = new HbMainWindow;
       
   310     mWidget = new HgGrid(Qt::Horizontal);
       
   311     mWindow->addView(mWidget);
       
   312     QVERIFY(mWidget->model() == 0);
       
   313 
       
   314     TestModel model1;
       
   315     model1.generateItems(10);
       
   316     mWidget->setModel(&model1);
       
   317     QVERIFY(&model1 == mWidget->model());
       
   318 
       
   319     mWindow->show();
       
   320 
       
   321     QTest::qWait(2000);
       
   322 
       
   323     TestModel model2;
       
   324     model2.generateItems(20);
       
   325     mWidget->setModel(&model2);
       
   326     QVERIFY(&model2 == mWidget->model());
       
   327 
       
   328     QTest::qWait(2000);
       
   329 
       
   330     mWidget->setModel(0);
       
   331     QVERIFY(mWidget->model() == 0);
       
   332 
       
   333     delete mWindow;
       
   334     mWindow = 0;
       
   335 }
       
   336 
   287 void TestGanesWidgets::test_panGridLandscape()
   337 void TestGanesWidgets::test_panGridLandscape()
   288 {
   338 {
   289     mWindow = new HbMainWindow;
   339     mWindow = new HbMainWindow;
   290     mWidget = new HgGrid(Qt::Horizontal);
   340     mWidget = new HgGrid(Qt::Horizontal);
   291     TestModel model;
   341     TestModel model;
   711 
   761 
   712     QVERIFY(mWidget->selectionModel());
   762     QVERIFY(mWidget->selectionModel());
   713     qRegisterMetaType<QModelIndex>("QModelIndex");
   763     qRegisterMetaType<QModelIndex>("QModelIndex");
   714     QSignalSpy currentItemSpy(mWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)));
   764     QSignalSpy currentItemSpy(mWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)));
   715 
   765 
   716     QTest::qWait(2000);
   766     QTest::qWait(default_delay);
   717 
   767 
   718     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   768     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   719 
   769 
   720     mWidget->setCurrentIndex(model.index(7, 0));
   770     mWidget->setCurrentIndex(model.index(7, 0));
   721     QVERIFY(mWidget->currentIndex() == model.index(7, 0));
   771     QVERIFY(mWidget->currentIndex() == model.index(7, 0));
   723     mWidget->setCurrentIndex(QModelIndex());
   773     mWidget->setCurrentIndex(QModelIndex());
   724     QVERIFY(!mWidget->currentIndex().isValid());
   774     QVERIFY(!mWidget->currentIndex().isValid());
   725 
   775 
   726     currentItemSpy.clear();
   776     currentItemSpy.clear();
   727     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos1, 100);
   777     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos1, 100);
   728     QTest::qWait(1000);
   778     QTest::qWait(default_delay);
   729     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   779     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   730     QVERIFY(currentItemSpy.count() == 1);
   780     QVERIFY(currentItemSpy.count() == 1);
   731     QVERIFY(currentItemSpy.at(0).count() > 0);
   781     QVERIFY(currentItemSpy.at(0).count() > 0);
   732     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(0, 0));
   782     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(0, 0));
   733 
   783 
   734     currentItemSpy.clear();
   784     currentItemSpy.clear();
   735     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100);
   785     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100);
   736     QTest::qWait(1000);
   786     QTest::qWait(default_delay);
   737     QVERIFY(mWidget->currentIndex() == model.index(1, 0));
   787     QVERIFY(mWidget->currentIndex() == model.index(1, 0));
   738     QVERIFY(currentItemSpy.count() == 1);
   788     QVERIFY(currentItemSpy.count() == 1);
   739     QVERIFY(currentItemSpy.at(0).count() > 0);
   789     QVERIFY(currentItemSpy.at(0).count() > 0);
   740     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(1, 0));
   790     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(1, 0));
   741 
   791 
   742     currentItemSpy.clear();
   792     currentItemSpy.clear();
   743     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100);
   793     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100);
   744     QTest::qWait(1000);
   794     QTest::qWait(default_delay);
   745     QVERIFY(mWidget->currentIndex() == model.index(2, 0));
   795     QVERIFY(mWidget->currentIndex() == model.index(2, 0));
   746     QVERIFY(currentItemSpy.count() == 1);
   796     QVERIFY(currentItemSpy.count() == 1);
   747     QVERIFY(currentItemSpy.at(0).count() > 0);
   797     QVERIFY(currentItemSpy.at(0).count() > 0);
   748     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(2, 0));
   798     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(2, 0));
   749 
   799 
   750     currentItemSpy.clear();
   800     currentItemSpy.clear();
   751     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100);
   801     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos2, 100);
   752     QTest::qWait(1000);
   802     QTest::qWait(default_delay);
   753     QVERIFY(mWidget->currentIndex() == model.index(3, 0));
   803     QVERIFY(mWidget->currentIndex() == model.index(3, 0));
   754     QVERIFY(currentItemSpy.count() == 1);
   804     QVERIFY(currentItemSpy.count() == 1);
   755     QVERIFY(currentItemSpy.at(0).count() > 0);
   805     QVERIFY(currentItemSpy.at(0).count() > 0);
   756     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(3, 0));
   806     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(3, 0));
   757 
   807 
   758     currentItemSpy.clear();
   808     currentItemSpy.clear();
   759     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   809     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   760     QTest::qWait(1000);
   810     QTest::qWait(default_delay);
   761     QVERIFY(mWidget->currentIndex() == model.index(2, 0));
   811     QVERIFY(mWidget->currentIndex() == model.index(2, 0));
   762     QVERIFY(currentItemSpy.count() == 1);
   812     QVERIFY(currentItemSpy.count() == 1);
   763     QVERIFY(currentItemSpy.at(0).count() > 0);
   813     QVERIFY(currentItemSpy.at(0).count() > 0);
   764     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(2, 0));
   814     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(2, 0));
   765 
   815 
   766     currentItemSpy.clear();
   816     currentItemSpy.clear();
   767     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   817     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   768     QTest::qWait(1000);
   818     QTest::qWait(default_delay);
   769     QVERIFY(mWidget->currentIndex() == model.index(1, 0));
   819     QVERIFY(mWidget->currentIndex() == model.index(1, 0));
   770     QVERIFY(currentItemSpy.count() == 1);
   820     QVERIFY(currentItemSpy.count() == 1);
   771     QVERIFY(currentItemSpy.at(0).count() > 0);
   821     QVERIFY(currentItemSpy.at(0).count() > 0);
   772     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(1, 0));
   822     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(1, 0));
   773 
   823 
   774     currentItemSpy.clear();
   824     currentItemSpy.clear();
   775     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   825     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   776     QTest::qWait(1000);
   826     QTest::qWait(default_delay);
   777     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   827     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   778     QVERIFY(currentItemSpy.count() == 1);
   828     QVERIFY(currentItemSpy.count() == 1);
   779     QVERIFY(currentItemSpy.at(0).count() > 0);
   829     QVERIFY(currentItemSpy.at(0).count() > 0);
   780     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(0, 0));
   830     QVERIFY(qvariant_cast<QModelIndex>(currentItemSpy.at(0).at(0)) == model.index(0, 0));
   781 
   831 
   782     currentItemSpy.clear();
   832     currentItemSpy.clear();
   783     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   833     HbAutoTest::mouseClick((HbAutoTestMainWindow*)mWindow, mWidget, pos3, 100);
   784     QTest::qWait(1000);
   834     QTest::qWait(default_delay);
   785     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   835     QVERIFY(mWidget->currentIndex() == model.index(0, 0));
   786     QVERIFY(currentItemSpy.count() == 0);
   836     QVERIFY(currentItemSpy.count() == 0);
   787 
   837 
   788     QTest::qWait(2000);
   838     QTest::qWait(default_delay);
   789 
   839 
   790     delete mWindow;
   840     delete mWindow;
   791     mWindow = 0;
   841     mWindow = 0;
   792 }
   842 }
   793 
   843 
  1277     mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working
  1327     mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working
  1278     mWidget = new HgMediawall();
  1328     mWidget = new HgMediawall();
  1279 
  1329 
  1280     QList<QModelIndex> requestedIndexes;
  1330     QList<QModelIndex> requestedIndexes;
  1281     TestModel model(&requestedIndexes);
  1331     TestModel model(&requestedIndexes);
  1282     model.generateItems(120);
  1332     model.generateItems(110);
  1283     mWidget->setModel(&model);
  1333     mWidget->setModel(&model);
  1284     mWindow->addView(mWidget);
  1334     mWindow->addView(mWidget);
  1285     mWindow->show();
  1335     mWindow->show();
  1286 
  1336 
  1287     QTest::qWait(2000);
  1337     QTest::qWait(2000);
  1288 
  1338 
  1289     QVERIFY(requestedIndexes.count() == 40); // Scroll buffer size in coverflow mode is assumed to be 40
  1339     QVERIFY(requestedIndexes.count() == 30); // Scroll buffer size in coverflow mode is assumed to be 30
  1290     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1340     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1291     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1341     QVERIFY(requestedIndexes.back() == model.index(29, 0));
  1292     requestedIndexes.clear();
  1342     requestedIndexes.clear();
  1293 
  1343 
  1294     // Move buffer to the end of items
  1344     // Move buffer to the end of items
  1295     mWidget->scrollTo(model.index(119, 0));
  1345     mWidget->setCurrentIndex(model.index(95, 0));
       
  1346     mWidget->scrollTo(model.index(95, 0));
  1296     QTest::qWait(1000);
  1347     QTest::qWait(1000);
  1297     requestedIndexes.clear();
  1348     requestedIndexes.clear();
  1298 
  1349 
  1299     // Add one item to beginning of buffer
  1350     // Add one item to beginning of buffer
  1300     model.insertItems(80, 1);
  1351     model.insertItems(80, 1);
  1301     QTest::qWait(1000);
  1352     QTest::qWait(1000);
  1302     QVERIFY(requestedIndexes.count() == 0); // New item falls outside of buffer as buffer is moved up
  1353     QVERIFY(requestedIndexes.count() == 0); // Buffer is moved up to 81
  1303     requestedIndexes.clear();
  1354     requestedIndexes.clear();
  1304     // Last item is now 120
  1355     // Last item is now 110
  1305 
  1356 
  1306     // Add many items to beginning of buffer
  1357     // Add many items to beginning of buffer
  1307     model.insertItems(81, 4);
  1358     model.insertItems(81, 4);
  1308     QTest::qWait(1000);
  1359     QTest::qWait(1000);
  1309     QVERIFY(requestedIndexes.count() == 0); // New items falls outside of buffer as buffer is moved up
  1360     QVERIFY(requestedIndexes.count() == 0); // // Buffer is moved up to 85
  1310     requestedIndexes.clear();
  1361     requestedIndexes.clear();
  1311     // Last item is now 124
  1362     // Last item is now 114
  1312 
  1363 
  1313     // Add one item to the end
  1364     // Add one item to the end of the buffer
  1314     model.insertItems(124, 1);
  1365     model.insertItems(114, 1);
  1315     QTest::qWait(1000);
  1366     QTest::qWait(1000);
  1316     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1367     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1317     QVERIFY(requestedIndexes.front() == model.index(124, 0));
  1368     QVERIFY(requestedIndexes.front() == model.index(114, 0));
  1318     requestedIndexes.clear();
  1369     requestedIndexes.clear();
  1319     // Last item is now 125
  1370     // Last item is now 115
  1320 
  1371 
  1321     // Add many items to the end
  1372     // Add many items to the end
  1322     model.insertItems(125, 4);
  1373     model.insertItems(111, 4);
  1323     QTest::qWait(1000);
  1374     QTest::qWait(1000);
  1324     QVERIFY(requestedIndexes.count() == 4); // The new items are requested
  1375     QVERIFY(requestedIndexes.count() == 4); // The new items are requested
  1325     QVERIFY(requestedIndexes.front() == model.index(125, 0));
  1376     QVERIFY(requestedIndexes.front() == model.index(111, 0));
  1326     QVERIFY(requestedIndexes.back() == model.index(128, 0));
  1377     QVERIFY(requestedIndexes.back() == model.index(114, 0));
  1327     requestedIndexes.clear();
  1378     requestedIndexes.clear();
  1328     // Last item is now 129
  1379     // Last item is now 119
  1329 
  1380 
  1330     // Add one item to middle of buffer
  1381     // Add one item to middle of buffer
  1331     model.insertItems(110, 1);
  1382     model.insertItems(100, 1);
  1332     QTest::qWait(1000);
  1383     QTest::qWait(1000);
  1333     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1384     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1334     QVERIFY(requestedIndexes.front() == model.index(110, 0));
  1385     QVERIFY(requestedIndexes.front() == model.index(100, 0));
  1335     requestedIndexes.clear();
  1386     requestedIndexes.clear();
  1336     // Last item is now 130
  1387     // Last item is now 130
  1337 
  1388 
  1338     // Add many items to middle of buffer
  1389     // Add many items to middle of buffer
  1339     model.insertItems(110, 4);
  1390     model.insertItems(100, 4);
  1340     QTest::qWait(1000);
  1391     QTest::qWait(1000);
  1341     QVERIFY(requestedIndexes.count() == 4); // The new items are requested
  1392     QVERIFY(requestedIndexes.count() == 4); // The new items are requested
  1342     QVERIFY(requestedIndexes.front() == model.index(110, 0));
  1393     QVERIFY(requestedIndexes.front() == model.index(100, 0));
  1343     QVERIFY(requestedIndexes.back() == model.index(113, 0));
  1394     QVERIFY(requestedIndexes.back() == model.index(103, 0));
  1344     requestedIndexes.clear();
  1395     requestedIndexes.clear();
  1345     // Last item is now 134
  1396     // Last item is now 134
  1346 
  1397 
  1347     // Add items to the buffer limit (beginning of buffer)
  1398     // Add items to the buffer limit (beginning of buffer)
  1348     model.insertItems(90, 20);
  1399     model.insertItems(70, 20);
  1349     QTest::qWait(1000);
  1400     QTest::qWait(1000);
  1350     QVERIFY(requestedIndexes.count() == 0); // New item falls outside of buffer as buffer is moved up
  1401     QVERIFY(requestedIndexes.count() == 0); // New item falls outside of buffer as buffer is moved up
  1351     // Last item is now 154
  1402     // Last item is now 154
  1352 
  1403 
  1353     // Add items to outside of buffer (before buffer)
  1404     // Add items to outside of buffer (before buffer)
  1355     QTest::qWait(1000);
  1406     QTest::qWait(1000);
  1356     QVERIFY(requestedIndexes.count() == 0); // The new items are not requested
  1407     QVERIFY(requestedIndexes.count() == 0); // The new items are not requested
  1357     requestedIndexes.clear();
  1408     requestedIndexes.clear();
  1358 
  1409 
  1359     // Move buffer to the beginning of items
  1410     // Move buffer to the beginning of items
  1360     mWidget->scrollTo(model.index(0, 0));
  1411     mWidget->setCurrentIndex(model.index(15, 0));
       
  1412     mWidget->scrollTo(model.index(15, 0));
  1361     QTest::qWait(1000);
  1413     QTest::qWait(1000);
  1362     requestedIndexes.clear();
  1414     requestedIndexes.clear();
  1363 
  1415 
  1364     // Add one item to beginning
  1416     // Add one item to beginning
  1365     model.insertItems(0, 1);
  1417     model.insertItems(0, 1);
  1366     QTest::qWait(1000);
  1418     QTest::qWait(1000);
       
  1419     QVERIFY(requestedIndexes.count() == 0); // Buffer is moved up
       
  1420 
       
  1421     // Add many items to beginning
       
  1422     model.insertItems(1, 5);
       
  1423     QTest::qWait(1000);
       
  1424     QVERIFY(requestedIndexes.count() == 0); // Buffer is moved up
       
  1425 
       
  1426     // Add one item to middle of buffer
       
  1427     model.insertItems(10, 1);
       
  1428     QTest::qWait(1000);
  1367     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1429     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1368     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1430     QVERIFY(requestedIndexes.front() == model.index(10, 0));
  1369     requestedIndexes.clear();
  1431     requestedIndexes.clear();
  1370 
  1432 
  1371     // Add many items to beginning
  1433     // Add many items to middle of buffer
  1372     model.insertItems(0, 5);
  1434     model.insertItems(10, 5);
  1373     QTest::qWait(1000);
  1435     QTest::qWait(1000);
  1374     QVERIFY(requestedIndexes.count() == 5); // The new items are requested
  1436     QVERIFY(requestedIndexes.count() == 5); // The new items are requested
  1375     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1437     QVERIFY(requestedIndexes.front() == model.index(10, 0));
  1376     QVERIFY(requestedIndexes.back() == model.index(4, 0));
  1438     QVERIFY(requestedIndexes.back() == model.index(14, 0));
  1377     requestedIndexes.clear();
  1439     requestedIndexes.clear();
  1378 
  1440 
  1379     // Add one item to middle of buffer
  1441     // Add one item to end of buffer
  1380     model.insertItems(20, 1);
  1442     model.insertItems(35, 1);
  1381     QTest::qWait(1000);
  1443     QTest::qWait(1000);
  1382     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1444     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
  1383     QVERIFY(requestedIndexes.front() == model.index(20, 0));
  1445     QVERIFY(requestedIndexes.front() == model.index(35, 0));
  1384     requestedIndexes.clear();
       
  1385 
       
  1386     // Add many items to middle of buffer
       
  1387     model.insertItems(20, 5);
       
  1388     QTest::qWait(1000);
       
  1389     QVERIFY(requestedIndexes.count() == 5); // The new items are requested
       
  1390     QVERIFY(requestedIndexes.front() == model.index(20, 0));
       
  1391     QVERIFY(requestedIndexes.back() == model.index(24, 0));
       
  1392     requestedIndexes.clear();
       
  1393 
       
  1394     // Add one item to end of buffer
       
  1395     model.insertItems(39, 1);
       
  1396     QTest::qWait(1000);
       
  1397     QVERIFY(requestedIndexes.count() == 1); // The new item is requested
       
  1398     QVERIFY(requestedIndexes.front() == model.index(39, 0));
       
  1399     requestedIndexes.clear();
  1446     requestedIndexes.clear();
  1400 
  1447 
  1401     // Add many items to end of buffer
  1448     // Add many items to end of buffer
  1402     model.insertItems(30, 10);
  1449     model.insertItems(26, 10);
  1403     QTest::qWait(1000);
  1450     QTest::qWait(1000);
  1404     QVERIFY(requestedIndexes.count() == 10); // The new items are requested
  1451     QVERIFY(requestedIndexes.count() == 10); // The new items are requested
  1405     QVERIFY(requestedIndexes.front() == model.index(30, 0));
  1452     QVERIFY(requestedIndexes.front() == model.index(26, 0));
  1406     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1453     QVERIFY(requestedIndexes.back() == model.index(35, 0));
  1407     requestedIndexes.clear();
  1454     requestedIndexes.clear();
  1408 
  1455 
  1409     // Add items to outside of buffer (after buffer)
  1456     // Add items to outside of buffer (after buffer)
       
  1457     model.insertItems(50, 10);
       
  1458     QTest::qWait(1000);
       
  1459     QVERIFY(requestedIndexes.count() == 0); // The new items are not requested
       
  1460     requestedIndexes.clear();
       
  1461 
       
  1462     // Add items to the buffer limit (end of buffer)
       
  1463     model.insertItems(31, 10);
       
  1464     QTest::qWait(1000);
       
  1465     QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested
       
  1466     QVERIFY(requestedIndexes.front() == model.index(31, 0));
       
  1467     QVERIFY(requestedIndexes.back() == model.index(35, 0));
       
  1468 
       
  1469     // Move buffer to the middle of items
       
  1470     mWidget->setCurrentIndex(model.index(60, 0));
       
  1471     mWidget->scrollTo(model.index(60, 0));
       
  1472     QTest::qWait(1000);
       
  1473     requestedIndexes.clear();
       
  1474 
       
  1475     // Add items to the buffer limit (beginning of buffer)
  1410     model.insertItems(40, 10);
  1476     model.insertItems(40, 10);
  1411     QTest::qWait(1000);
  1477     QTest::qWait(1000);
  1412     QVERIFY(requestedIndexes.count() == 0); // The new items are not requested
  1478     QVERIFY(requestedIndexes.count() == 0); // The buffer is moved up
  1413     requestedIndexes.clear();
       
  1414 
       
  1415     // Add items to the buffer limit (end of buffer)
       
  1416     model.insertItems(35, 10);
       
  1417     QTest::qWait(1000);
       
  1418     QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested
       
  1419     QVERIFY(requestedIndexes.front() == model.index(35, 0));
       
  1420     QVERIFY(requestedIndexes.back() == model.index(39, 0));
       
  1421 
       
  1422     // Move buffer to the middle of items
       
  1423     mWidget->scrollTo(model.index(60, 0));
       
  1424     QTest::qWait(1000);
       
  1425     requestedIndexes.clear();
       
  1426 
       
  1427     // Add items to the buffer limit (beginning of buffer)
       
  1428     model.insertItems(35, 10);
       
  1429     QTest::qWait(1000);
       
  1430     QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested
       
  1431     QVERIFY(requestedIndexes.front() == model.index(40, 0));
       
  1432     QVERIFY(requestedIndexes.back() == model.index(44, 0));
       
  1433 
  1479 
  1434     // Add items over the whole buffer
  1480     // Add items over the whole buffer
  1435     model.insertItems(35, 50);
  1481     model.insertItems(40, 50);
  1436     QTest::qWait(1000);
  1482     QTest::qWait(1000);
  1437     QVERIFY(requestedIndexes.count() == 40); // The new items inside buffer are requested
  1483     QVERIFY(requestedIndexes.count() == 0); // The buffer is moved up
  1438     QVERIFY(requestedIndexes.front() == model.index(40, 0));
       
  1439     QVERIFY(requestedIndexes.back() == model.index(79, 0));
       
  1440 
  1484 
  1441     QTest::qWait(2000);
  1485     QTest::qWait(2000);
  1442 
  1486 
  1443     delete mWindow;
  1487     delete mWindow;
  1444     mWindow = 0;
  1488     mWindow = 0;
  1453     mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working
  1497     mWindow->viewport()->grabGesture(Qt::TapGesture); // Add TapAndHoldGesture once it's working
  1454     mWidget = new HgMediawall();
  1498     mWidget = new HgMediawall();
  1455 
  1499 
  1456     QList<QModelIndex> requestedIndexes;
  1500     QList<QModelIndex> requestedIndexes;
  1457     TestModel model(&requestedIndexes);
  1501     TestModel model(&requestedIndexes);
  1458     model.generateItems(240);
  1502     model.generateItems(230);
  1459     mWidget->setModel(&model);
  1503     mWidget->setModel(&model);
  1460     mWindow->addView(mWidget);
  1504     mWindow->addView(mWidget);
  1461     mWindow->show();
  1505     mWindow->show();
  1462 
  1506 
  1463     QTest::qWait(2000);
  1507     QTest::qWait(2000);
  1464 
  1508 
  1465     QVERIFY(requestedIndexes.count() == 40); // Scroll buffer size in coverflow mode is assumed to be 40
  1509     QVERIFY(requestedIndexes.count() == 30); // Scroll buffer size in coverflow mode is assumed to be 40
  1466     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1510     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1467     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1511     QVERIFY(requestedIndexes.back() == model.index(29, 0));
  1468     requestedIndexes.clear();
  1512     requestedIndexes.clear();
  1469 
  1513 
  1470     // Move buffer to the end of items
  1514     // Move buffer to the end of items
  1471     mWidget->scrollTo(model.index(239, 0));
  1515     mWidget->setCurrentIndex(model.index(229, 0));
       
  1516     mWidget->scrollTo(model.index(229, 0));
  1472     QTest::qWait(1000);
  1517     QTest::qWait(1000);
  1473     requestedIndexes.clear();
  1518     requestedIndexes.clear();
  1474 
  1519 
  1475     // Remove one item from the beginning of buffer
  1520     // Remove one item from the beginning of buffer
  1476     model.removeItems(200, 1);
  1521     model.removeItems(200, 1);
  1477     QTest::qWait(1000);
  1522     QTest::qWait(1000);
  1478     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1523     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1479     QVERIFY(requestedIndexes.front() == model.index(199, 0));
  1524     QVERIFY(requestedIndexes.front() == model.index(199, 0));
  1480     requestedIndexes.clear();
  1525     requestedIndexes.clear();
  1481     // Last item is now 238
  1526     // Last item is now 228
  1482 
  1527 
  1483     // Remove many items from beginning of buffer
  1528     // Remove many items from beginning of buffer
  1484     model.removeItems(199, 4);
  1529     model.removeItems(199, 4);
  1485     QTest::qWait(1000);
  1530     QTest::qWait(1000);
  1486     QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones
  1531     QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones
  1487     QVERIFY(requestedIndexes.front() == model.index(195, 0));
  1532     QVERIFY(requestedIndexes.front() == model.index(195, 0));
  1488     QVERIFY(requestedIndexes.back() == model.index(198, 0));
  1533     QVERIFY(requestedIndexes.back() == model.index(198, 0));
  1489     requestedIndexes.clear();
  1534     requestedIndexes.clear();
  1490     // Last item is now 234
  1535     // Last item is now 224
  1491 
  1536 
  1492     // Remove one item from the end
  1537     // Remove one item from the end
  1493     model.removeItems(234, 1);
  1538     model.removeItems(224, 1);
  1494     QTest::qWait(1000);
  1539     QTest::qWait(1000);
  1495     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1540     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1496     QVERIFY(requestedIndexes.front() == model.index(194, 0));
  1541     QVERIFY(requestedIndexes.front() == model.index(194, 0));
  1497     requestedIndexes.clear();
  1542     requestedIndexes.clear();
  1498     // Last item is now 233
  1543     // Last item is now 223
  1499 
  1544 
  1500     // Remove many items from the end
  1545     // Remove many items from the end
  1501     model.removeItems(230, 4);
  1546     model.removeItems(220, 4);
  1502     QTest::qWait(1000);
  1547     QTest::qWait(1000);
  1503     QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones
  1548     QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones
  1504     QVERIFY(requestedIndexes.front() == model.index(190, 0));
  1549     QVERIFY(requestedIndexes.front() == model.index(190, 0));
  1505     QVERIFY(requestedIndexes.back() == model.index(193, 0));
  1550     QVERIFY(requestedIndexes.back() == model.index(193, 0));
  1506     requestedIndexes.clear();
  1551     requestedIndexes.clear();
  1507     // Last item is now 229
  1552     // Last item is now 219
  1508 
  1553 
  1509     // Remove one item from the middle of buffer
  1554     // Remove one item from the middle of buffer
  1510     model.removeItems(210, 1);
  1555     model.removeItems(210, 1);
  1511     QTest::qWait(1000);
  1556     QTest::qWait(1000);
  1512     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1557     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1513     QVERIFY(requestedIndexes.front() == model.index(189, 0));
  1558     QVERIFY(requestedIndexes.front() == model.index(189, 0));
  1514     requestedIndexes.clear();
  1559     requestedIndexes.clear();
  1515     // Last item is now 228
  1560     // Last item is now 218
  1516 
  1561 
  1517     // Remove many items from the middle of buffer
  1562     // Remove many items from the middle of buffer
  1518     model.removeItems(210, 4);
  1563     model.removeItems(210, 4);
  1519     QTest::qWait(1000);
  1564     QTest::qWait(1000);
  1520     QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones
  1565     QVERIFY(requestedIndexes.count() == 4); // New items are fetched to replace the removed ones
  1521     QVERIFY(requestedIndexes.front() == model.index(185, 0));
  1566     QVERIFY(requestedIndexes.front() == model.index(185, 0));
  1522     QVERIFY(requestedIndexes.back() == model.index(188, 0));
  1567     QVERIFY(requestedIndexes.back() == model.index(188, 0));
  1523     requestedIndexes.clear();
  1568     requestedIndexes.clear();
  1524     // Last item is now 224
  1569     // Last item is now 214
  1525 
  1570 
  1526     // Remove items from the buffer limit (beginning of buffer)
  1571     // Remove items from the buffer limit (beginning of buffer)
  1527     model.removeItems(180, 10);
  1572     model.removeItems(180, 10);
  1528     QTest::qWait(1000);
  1573     QTest::qWait(1000);
  1529     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones
  1574     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones
  1530     QVERIFY(requestedIndexes.front() == model.index(175, 0));
  1575     QVERIFY(requestedIndexes.front() == model.index(180, 0));
  1531     QVERIFY(requestedIndexes.back() == model.index(179, 0));
  1576     QVERIFY(requestedIndexes.back() == model.index(184, 0));
  1532     requestedIndexes.clear();
  1577     requestedIndexes.clear();
  1533     // Last item is now 214
  1578     // Last item is now 204
  1534 
  1579 
  1535     // Remove items from outside of buffer (before buffer)
  1580     // Remove items from outside of buffer (before buffer)
  1536     model.removeItems(0, 10);
  1581     model.removeItems(0, 10);
  1537     QTest::qWait(1000);
  1582     QTest::qWait(1000);
  1538     QVERIFY(requestedIndexes.count() == 0); // Buffer is not moved
  1583     QVERIFY(requestedIndexes.count() == 0); // Buffer is not moved
  1539     requestedIndexes.clear();
  1584     requestedIndexes.clear();
  1540     // Last item is now 204
  1585     // Last item is now 194
  1541 
  1586 
  1542     // Move buffer to the beginning of items
  1587     // Move buffer to the beginning of items
       
  1588     mWidget->setCurrentIndex(model.index(0, 0));
  1543     mWidget->scrollTo(model.index(0, 0));
  1589     mWidget->scrollTo(model.index(0, 0));
  1544     QTest::qWait(1000);
  1590     QTest::qWait(1000);
  1545     requestedIndexes.clear();
  1591     requestedIndexes.clear();
  1546 
  1592 
  1547     // Remove one item from beginning
  1593     // Remove one item from beginning
  1548     model.removeItems(0, 1);
  1594     model.removeItems(0, 1);
  1549     QTest::qWait(1000);
  1595     QTest::qWait(1000);
  1550     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1596     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1551     QVERIFY(requestedIndexes.front() == model.index(39, 0));
  1597     QVERIFY(requestedIndexes.front() == model.index(29, 0));
  1552     requestedIndexes.clear();
  1598     requestedIndexes.clear();
  1553     // Last item is now 203
  1599     // Last item is now 193
  1554 
  1600 
  1555     // Remove many items from beginning
  1601     // Remove many items from beginning
  1556     model.removeItems(0, 5);
  1602     model.removeItems(0, 5);
  1557     QTest::qWait(1000);
  1603     QTest::qWait(1000);
  1558     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones
  1604     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones
  1559     QVERIFY(requestedIndexes.front() == model.index(35, 0));
  1605     QVERIFY(requestedIndexes.front() == model.index(25, 0));
  1560     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1606     QVERIFY(requestedIndexes.back() == model.index(29, 0));
  1561     requestedIndexes.clear();
  1607     requestedIndexes.clear();
  1562     // Last item is now 198
  1608     // Last item is now 188
  1563 
  1609 
  1564     // Remove one item from the middle of buffer
  1610     // Remove one item from the middle of buffer
  1565     model.removeItems(20, 1);
  1611     model.removeItems(15, 1);
  1566     QTest::qWait(1000);
  1612     QTest::qWait(1000);
  1567     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1613     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1568     QVERIFY(requestedIndexes.front() == model.index(39, 0));
  1614     QVERIFY(requestedIndexes.front() == model.index(29, 0));
  1569     requestedIndexes.clear();
  1615     requestedIndexes.clear();
  1570     // Last item is now 197
  1616     // Last item is now 187
  1571 
  1617 
  1572     // Remove many items from the middle of buffer
  1618     // Remove many items from the middle of buffer
  1573     model.removeItems(20, 5);
  1619     model.removeItems(15, 5);
  1574     QTest::qWait(1000);
  1620     QTest::qWait(1000);
  1575     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones
  1621     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the removed ones
  1576     QVERIFY(requestedIndexes.front() == model.index(35, 0));
  1622     QVERIFY(requestedIndexes.front() == model.index(25, 0));
  1577     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1623     QVERIFY(requestedIndexes.back() == model.index(29, 0));
  1578     requestedIndexes.clear();
  1624     requestedIndexes.clear();
  1579     // Last item is now 192
  1625     // Last item is now 182
  1580 
  1626 
  1581     // Remove one item from the end of buffer
  1627     // Remove one item from the end of buffer
  1582     model.removeItems(39, 1);
  1628     model.removeItems(29, 1);
  1583     QTest::qWait(1000);
  1629     QTest::qWait(1000);
  1584     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1630     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the removed one
  1585     QVERIFY(requestedIndexes.front() == model.index(39, 0));
  1631     QVERIFY(requestedIndexes.front() == model.index(29, 0));
  1586     requestedIndexes.clear();
  1632     requestedIndexes.clear();
  1587     // Last item is now 191
  1633     // Last item is now 181
  1588 
  1634 
  1589     // Remove many items from the end of buffer
  1635     // Remove many items from the end of buffer
  1590     model.removeItems(30, 10);
  1636     model.removeItems(20, 10);
  1591     QTest::qWait(1000);
  1637     QTest::qWait(1000);
  1592     QVERIFY(requestedIndexes.count() == 10); // New items are fetched to replace the removed ones
  1638     QVERIFY(requestedIndexes.count() == 10); // New items are fetched to replace the removed ones
  1593     QVERIFY(requestedIndexes.front() == model.index(30, 0));
  1639     QVERIFY(requestedIndexes.front() == model.index(20, 0));
  1594     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1640     QVERIFY(requestedIndexes.back() == model.index(29, 0));
  1595     requestedIndexes.clear();
  1641     requestedIndexes.clear();
  1596     // Last item is now 181
  1642     // Last item is now 171
  1597 
  1643 
  1598     // Remove items from outside of buffer (after buffer)
  1644     // Remove items from outside of buffer (after buffer)
  1599     model.removeItems(50, 10);
  1645     model.removeItems(50, 10);
  1600     QTest::qWait(1000);
  1646     QTest::qWait(1000);
  1601     QVERIFY(requestedIndexes.count() == 0); // Buffer is not updated
  1647     QVERIFY(requestedIndexes.count() == 0); // Buffer is not updated
  1602     requestedIndexes.clear();
  1648     requestedIndexes.clear();
  1603     // Last item is now 171
  1649     // Last item is now 161
  1604 
  1650 
  1605     // Remove items from the buffer limit (end of buffer)
  1651     // Remove items from the buffer limit (end of buffer)
  1606     model.insertItems(35, 10);
  1652     model.removeItems(25, 10);
  1607     QTest::qWait(1000);
  1653     QTest::qWait(1000);
  1608     QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested
  1654     QVERIFY(requestedIndexes.count() == 5); // The new items inside buffer are requested
  1609     QVERIFY(requestedIndexes.front() == model.index(35, 0));
  1655     QVERIFY(requestedIndexes.front() == model.index(25, 0));
  1610     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1656     QVERIFY(requestedIndexes.back() == model.index(29, 0));
  1611     // Last item is now 161
  1657     // Last item is now 151
  1612 
  1658 
  1613     // Move buffer to the middle of items
  1659     // Move buffer to the middle of items
  1614     mWidget->scrollTo(model.index(80, 0));
  1660     mWidget->setCurrentIndex(model.index(75, 0));
       
  1661     mWidget->scrollTo(model.index(75, 0));
  1615     QTest::qWait(1000);
  1662     QTest::qWait(1000);
  1616     requestedIndexes.clear();
  1663     requestedIndexes.clear();
  1617 
  1664 
  1618     // Remove items from the buffer limit (beginning of buffer)
  1665     // Remove items from the buffer limit (beginning of buffer)
  1619     model.removeItems(59, 2);
  1666     model.removeItems(59, 2);
  1620     QTest::qWait(1000);
  1667     QTest::qWait(1000);
  1621     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the one removed from the buffer
  1668     QVERIFY(requestedIndexes.count() == 1); // New item is fetched to replace the one removed from the buffer
  1622     QVERIFY(requestedIndexes.front() == model.index(99, 0));
  1669     QVERIFY(requestedIndexes.front() == model.index(88, 0)); // Buffer is moved forward, this is the last item
  1623     // Last item is now 159
  1670     requestedIndexes.clear();
       
  1671     // Last item is now 149
  1624 
  1672 
  1625     // Remove items over the whole buffer
  1673     // Remove items over the whole buffer
  1626     model.removeItems(55, 50);
  1674     model.removeItems(55, 50);
  1627     QTest::qWait(1000);
  1675     QTest::qWait(1000);
  1628     QVERIFY(requestedIndexes.count() == 40); // Whole buffer is updated
  1676     QVERIFY(requestedIndexes.count() == 30); // Whole buffer is updated
  1629     QVERIFY(requestedIndexes.front() == model.index(60, 0));
       
  1630     QVERIFY(requestedIndexes.back() == model.index(99, 0));
       
  1631 
  1677 
  1632     QTest::qWait(2000);
  1678     QTest::qWait(2000);
  1633 
  1679 
  1634     delete mWindow;
  1680     delete mWindow;
  1635     mWindow = 0;
  1681     mWindow = 0;
  1651     mWindow->addView(mWidget);
  1697     mWindow->addView(mWidget);
  1652     mWindow->show();
  1698     mWindow->show();
  1653 
  1699 
  1654     QTest::qWait(2000);
  1700     QTest::qWait(2000);
  1655 
  1701 
  1656     QVERIFY(requestedIndexes.count() == 40); // Scroll buffer size in coverflow mode is assumed to be 40
  1702     QVERIFY(requestedIndexes.count() == 30); // Scroll buffer size in coverflow mode is assumed to be 40
  1657     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1703     QVERIFY(requestedIndexes.front() == model.index(0, 0));
  1658     QVERIFY(requestedIndexes.back() == model.index(39, 0));
  1704     QVERIFY(requestedIndexes.back() == model.index(29, 0));
  1659     requestedIndexes.clear();
  1705     requestedIndexes.clear();
  1660 
  1706 
  1661     // Move one item forward
  1707     // Move one item forward
  1662     model.moveItems(0, 20, 1);
  1708     model.moveItems(0, 20, 1);
  1663     QTest::qWait(1000);
  1709     QTest::qWait(1000);
  1665 
  1711 
  1666     model.moveItems(0, 2, 1);
  1712     model.moveItems(0, 2, 1);
  1667     QTest::qWait(1000);
  1713     QTest::qWait(1000);
  1668     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1714     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1669 
  1715 
  1670     model.moveItems(0, 39, 1);
  1716     model.moveItems(0, 29, 1);
  1671     QTest::qWait(1000);
  1717     QTest::qWait(1000);
  1672     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1718     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1673 
  1719 
  1674     // Move many items forward
  1720     // Move many items forward
  1675     model.moveItems(0, 20, 5);
  1721     model.moveItems(0, 20, 5);
  1676     QTest::qWait(1000);
  1722     QTest::qWait(1000);
  1677     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1723     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1678 
  1724 
  1679     // Move one item backward
  1725     // Move one item backward
  1680     model.moveItems(39, 20, 1);
  1726     model.moveItems(29, 20, 1);
  1681     QTest::qWait(1000);
  1727     QTest::qWait(1000);
  1682     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1728     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1683 
  1729 
  1684     model.moveItems(39, 38, 1);
  1730     model.moveItems(29, 28, 1);
  1685     QTest::qWait(1000);
  1731     QTest::qWait(1000);
  1686     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1732     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1687 
  1733 
  1688     model.moveItems(39, 0, 1);
  1734     model.moveItems(29, 0, 1);
  1689     QTest::qWait(1000);
  1735     QTest::qWait(1000);
  1690     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1736     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1691 
  1737 
  1692     // Move many items backward
  1738     // Move many items backward
  1693     model.moveItems(30, 20, 10);
  1739     model.moveItems(20, 5, 10);
  1694     QTest::qWait(1000);
  1740     QTest::qWait(1000);
  1695     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1741     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1696 
  1742 
  1697     // This should do nothing
  1743     // This should do nothing
  1698     model.moveItems(20, 20, 1);
  1744     model.moveItems(20, 20, 1);
  1699     QTest::qWait(1000);
  1745     QTest::qWait(1000);
  1700     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1746     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1701 
  1747 
  1702     // Move items from the border of the buffer forward
  1748     // Move items from the border of the buffer forward
  1703     model.moveItems(35, 50, 10);
  1749     model.moveItems(25, 50, 10);
  1704     QTest::qWait(1000);
  1750     QTest::qWait(1000);
  1705     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the moved ones
  1751     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1706     QVERIFY(requestedIndexes.front() == model.index(35, 0));
       
  1707     QVERIFY(requestedIndexes.back() == model.index(39, 0));
       
  1708     requestedIndexes.clear();
  1752     requestedIndexes.clear();
  1709 
  1753 
  1710     // Move items from the border of the buffer backward
  1754     // Move items from the border of the buffer backward
  1711     model.moveItems(35, 20, 10);
  1755     model.moveItems(25, 10, 10);
  1712     QTest::qWait(1000);
  1756     QTest::qWait(1000);
  1713     QVERIFY(requestedIndexes.count() == 5); // Items that were originally outside of buffer are fetched
  1757     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1714     QVERIFY(requestedIndexes.front() == model.index(25, 0));
       
  1715     QVERIFY(requestedIndexes.back() == model.index(29, 0));
       
  1716     requestedIndexes.clear();
  1758     requestedIndexes.clear();
  1717 
  1759 
  1718     // Move items from the buffer outside it
  1760     // Move items from the buffer outside it
  1719     model.moveItems(20, 90, 10);
  1761     model.moveItems(20, 90, 10);
  1720     QTest::qWait(1000);
  1762     QTest::qWait(1000);
  1721     QVERIFY(requestedIndexes.count() == 10); // New items are fetched to replace the moved ones
  1763     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1722     QVERIFY(requestedIndexes.front() == model.index(30, 0));
       
  1723     QVERIFY(requestedIndexes.back() == model.index(39, 0));
       
  1724     requestedIndexes.clear();
  1764     requestedIndexes.clear();
  1725 
  1765 
  1726     // Move items from outside the buffer inside it
  1766     // Move items from outside the buffer inside it
  1727     model.moveItems(90, 20, 10);
  1767     model.moveItems(90, 15, 10);
  1728     QTest::qWait(1000);
  1768     QTest::qWait(1000);
  1729     QVERIFY(requestedIndexes.count() == 10); // Moved items are fetched
  1769     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1730     QVERIFY(requestedIndexes.front() == model.index(20, 0));
       
  1731     QVERIFY(requestedIndexes.back() == model.index(29, 0));
       
  1732     requestedIndexes.clear();
  1770     requestedIndexes.clear();
  1733 
  1771 
  1734     // Move buffer to the end of items
  1772     // Move buffer to the end of items
  1735     mWidget->scrollTo(model.index(119, 0));
  1773     mWidget->setCurrentIndex(model.index(110, 0));
       
  1774     mWidget->scrollTo(model.index(110, 0));
  1736     QTest::qWait(1000);
  1775     QTest::qWait(1000);
  1737     requestedIndexes.clear();
  1776     requestedIndexes.clear();
  1738 
  1777 
  1739     // Move one item forward
  1778     // Move one item forward
  1740     model.moveItems(80, 100, 1);
  1779     model.moveItems(90, 100, 1);
  1741     QTest::qWait(1000);
  1780     QTest::qWait(1000);
  1742     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1781     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1743 
  1782 
  1744     model.moveItems(80, 82, 1);
  1783     // Move buffer to the end of items
       
  1784     mWidget->setCurrentIndex(model.index(110, 0));
       
  1785     mWidget->scrollTo(model.index(110, 0));
       
  1786     QTest::qWait(1000);
       
  1787     requestedIndexes.clear();
       
  1788 
       
  1789     model.moveItems(90, 92, 1);
  1745     QTest::qWait(1000);
  1790     QTest::qWait(1000);
  1746     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1791     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1747 
  1792 
  1748     model.moveItems(80, 119, 1);
  1793     // Move buffer to the end of items
       
  1794     mWidget->setCurrentIndex(model.index(110, 0));
       
  1795     mWidget->scrollTo(model.index(110, 0));
       
  1796     QTest::qWait(1000);
       
  1797     requestedIndexes.clear();
       
  1798 
       
  1799     model.moveItems(90, 119, 1);
  1749     QTest::qWait(1000);
  1800     QTest::qWait(1000);
  1750     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1801     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1751 
  1802 
       
  1803     // Move buffer to the end of items
       
  1804     mWidget->setCurrentIndex(model.index(110, 0));
       
  1805     mWidget->scrollTo(model.index(110, 0));
       
  1806     QTest::qWait(1000);
       
  1807     requestedIndexes.clear();
       
  1808 
  1752     // Move many items forward
  1809     // Move many items forward
  1753     model.moveItems(80, 100, 5);
  1810     model.moveItems(90, 100, 5);
  1754     QTest::qWait(1000);
  1811     QTest::qWait(1000);
  1755     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1812     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
       
  1813 
       
  1814     // Move buffer to the end of items
       
  1815     mWidget->setCurrentIndex(model.index(120, 0));
       
  1816     mWidget->scrollTo(model.index(120, 0));
       
  1817     QTest::qWait(1000);
       
  1818     requestedIndexes.clear();
  1756 
  1819 
  1757     // Move one item backward
  1820     // Move one item backward
  1758     model.moveItems(119, 100, 1);
  1821     model.moveItems(119, 100, 1);
  1759     QTest::qWait(1000);
  1822     QTest::qWait(1000);
  1760     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1823     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1761 
  1824 
       
  1825     // Move buffer to the end of items
       
  1826     mWidget->setCurrentIndex(model.index(110, 0));
       
  1827     mWidget->scrollTo(model.index(120, 0));
       
  1828     QTest::qWait(1000);
       
  1829     requestedIndexes.clear();
       
  1830 
  1762     model.moveItems(119, 118, 1);
  1831     model.moveItems(119, 118, 1);
  1763     QTest::qWait(1000);
  1832     QTest::qWait(1000);
  1764     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1833     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1765 
  1834 
  1766     model.moveItems(119, 80, 1);
  1835     // Move buffer to the end of items
       
  1836     mWidget->setCurrentIndex(model.index(110, 0));
       
  1837     mWidget->scrollTo(model.index(110, 0));
       
  1838     QTest::qWait(1000);
       
  1839     requestedIndexes.clear();
       
  1840 
       
  1841     model.moveItems(119, 90, 1);
  1767     QTest::qWait(1000);
  1842     QTest::qWait(1000);
  1768     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1843     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
       
  1844 
       
  1845     // Move buffer to the end of items
       
  1846     mWidget->setCurrentIndex(model.index(110, 0));
       
  1847     mWidget->scrollTo(model.index(110, 0));
       
  1848     QTest::qWait(1000);
       
  1849     requestedIndexes.clear();
  1769 
  1850 
  1770     // Move many items backward
  1851     // Move many items backward
  1771     model.moveItems(110, 95, 10);
  1852     model.moveItems(110, 95, 10);
  1772     QTest::qWait(1000);
  1853     QTest::qWait(1000);
  1773     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1854     QVERIFY(requestedIndexes.count() == 0); // New items are not fetched as the changes happened inside the buffer
  1774 
  1855 
       
  1856     // Move buffer to the end of items
       
  1857     mWidget->setCurrentIndex(model.index(110, 0));
       
  1858     mWidget->scrollTo(model.index(110, 0));
       
  1859     QTest::qWait(1000);
       
  1860     requestedIndexes.clear();
       
  1861 
  1775     // Move items from the border of the buffer backward
  1862     // Move items from the border of the buffer backward
  1776     model.moveItems(75, 60, 10);
  1863     model.moveItems(85, 60, 10);
  1777     QTest::qWait(1000);
  1864     QTest::qWait(1000);
  1778     QVERIFY(requestedIndexes.count() == 5); // New items are fetched to replace the moved ones
  1865     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1779     QVERIFY(requestedIndexes.front() == model.index(80, 0));
  1866 
  1780     QVERIFY(requestedIndexes.back() == model.index(84, 0));
  1867     // Move buffer to the end of items
       
  1868     mWidget->setCurrentIndex(model.index(110, 0));
       
  1869     mWidget->scrollTo(model.index(110, 0));
       
  1870     QTest::qWait(1000);
  1781     requestedIndexes.clear();
  1871     requestedIndexes.clear();
  1782 
  1872 
  1783     // Move items from the border of the buffer forward
  1873     // Move items from the border of the buffer forward
  1784     model.moveItems(75, 100, 10);
  1874     model.moveItems(85, 100, 10);
  1785     QTest::qWait(1000);
  1875     QTest::qWait(1000);
  1786     QVERIFY(requestedIndexes.count() == 5); // Items that were originally outside of buffer are fetched
  1876     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1787     QVERIFY(requestedIndexes.front() == model.index(100, 0));
  1877 
  1788     QVERIFY(requestedIndexes.back() == model.index(104, 0));
  1878     // Move buffer to the end of items
       
  1879     mWidget->setCurrentIndex(model.index(110, 0));
       
  1880     mWidget->scrollTo(model.index(110, 0));
       
  1881     QTest::qWait(1000);
  1789     requestedIndexes.clear();
  1882     requestedIndexes.clear();
  1790 
  1883 
  1791     // Move items from the buffer outside it
  1884     // Move items from the buffer outside it
  1792     model.moveItems(100, 10, 10);
  1885     model.moveItems(100, 10, 10);
  1793     QTest::qWait(1000);
  1886     QTest::qWait(1000);
  1794     QVERIFY(requestedIndexes.count() == 10); // New items are fetched to replace the moved ones
  1887     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1795     QVERIFY(requestedIndexes.front() == model.index(80, 0));
  1888 
  1796     QVERIFY(requestedIndexes.back() == model.index(89, 0));
  1889     // Move buffer to the end of items
       
  1890     mWidget->setCurrentIndex(model.index(110, 0));
       
  1891     mWidget->scrollTo(model.index(110, 0));
       
  1892     QTest::qWait(1000);
  1797     requestedIndexes.clear();
  1893     requestedIndexes.clear();
  1798 
  1894 
  1799     // Move items from outside the buffer inside it
  1895     // Move items from outside the buffer inside it
  1800     model.moveItems(10, 100, 10);
  1896     model.moveItems(10, 100, 10);
  1801     QTest::qWait(1000);
  1897     QTest::qWait(1000);
  1802     QVERIFY(requestedIndexes.count() == 10); // Moved items are fetched
  1898     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1803     QVERIFY(requestedIndexes.front() == model.index(100, 0));
  1899 
  1804     QVERIFY(requestedIndexes.back() == model.index(109, 0));
  1900     // Move buffer to the end of items
       
  1901     mWidget->setCurrentIndex(model.index(110, 0));
       
  1902     mWidget->scrollTo(model.index(110, 0));
       
  1903     QTest::qWait(1000);
  1805     requestedIndexes.clear();
  1904     requestedIndexes.clear();
  1806 
  1905 
  1807     // Move buffer to the middle of items
  1906     // Move buffer to the middle of items
       
  1907     mWidget->setCurrentIndex(model.index(60, 0));
  1808     mWidget->scrollTo(model.index(60, 0));
  1908     mWidget->scrollTo(model.index(60, 0));
  1809     QTest::qWait(1000);
  1909     QTest::qWait(1000);
       
  1910 
       
  1911     // Move buffer to the end of items
       
  1912     mWidget->setCurrentIndex(model.index(60, 0));
       
  1913     mWidget->scrollTo(model.index(60, 0));
       
  1914     QTest::qWait(1000);
  1810     requestedIndexes.clear();
  1915     requestedIndexes.clear();
  1811 
  1916 
  1812     // Move items over the whole buffer forward
  1917     // Move items over the whole buffer forward
  1813     model.moveItems(35, 110, 50);
  1918     model.moveItems(40, 110, 50);
  1814     QTest::qWait(1000);
  1919     QTest::qWait(1000);
  1815     QVERIFY(requestedIndexes.count() == 40); // Whole buffer is updated
  1920     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1816     QVERIFY(requestedIndexes.front() == model.index(40, 0));
  1921 
  1817     QVERIFY(requestedIndexes.back() == model.index(79, 0));
  1922     // Move buffer to the middle of items
       
  1923     mWidget->setCurrentIndex(model.index(60, 0));
       
  1924     mWidget->scrollTo(model.index(60, 0));
       
  1925     QTest::qWait(1000);
       
  1926     requestedIndexes.clear();
  1818 
  1927 
  1819     // Move items over the whole buffer backward
  1928     // Move items over the whole buffer backward
  1820     model.moveItems(35, 10, 50);
  1929     model.moveItems(40, 10, 50);
  1821     QTest::qWait(1000);
  1930     QTest::qWait(1000);
  1822     QVERIFY(requestedIndexes.count() == 40); // Whole buffer is updated
  1931     QVERIFY(requestedIndexes.count() == 30); // The whole buffer is reset
  1823     QVERIFY(requestedIndexes.front() == model.index(40, 0));
  1932 
  1824     QVERIFY(requestedIndexes.back() == model.index(79, 0));
  1933     QTest::qWait(2000);
  1825 
  1934 
  1826     QTest::qWait(2000);
  1935     delete mWindow;
  1827 
  1936     mWindow = 0;
  1828     delete mWindow;
  1937 }
  1829     mWindow = 0;
  1938 
       
  1939 void TestGanesWidgets::test_labelPositionsCoverFlow()
       
  1940 {
       
  1941     mWindow = new HbMainWindow;
       
  1942     mMediawall = new HgMediawall();
       
  1943 
       
  1944     TestModel model;
       
  1945     model.generateItems(50);
       
  1946     mWindow->addView(mMediawall);
       
  1947     mMediawall->setModel(&model);
       
  1948     mWindow->show();
       
  1949 
       
  1950     mMediawall->setTitlePosition(HgMediawall::PositionNone);
       
  1951     mMediawall->setDescriptionPosition(HgMediawall::PositionNone);
       
  1952     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionNone);
       
  1953     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionNone);
       
  1954 
       
  1955     // This updates the title and description label. But how to test they are in correct positions?
       
  1956     mMediawall->setCurrentIndex(model.index(1, 0));
       
  1957     QTest::qWait(1000);
       
  1958 
       
  1959     mMediawall->setDescriptionPosition(HgMediawall::PositionAboveImage);
       
  1960     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionNone);
       
  1961     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionAboveImage);
       
  1962     mMediawall->setCurrentIndex(model.index(2, 0));
       
  1963     QTest::qWait(1000);
       
  1964     QVERIFY(checkLabelAt(mWindow, expected_label_pos_above_alone, "Secondary 2"));
       
  1965 
       
  1966     mMediawall->setDescriptionPosition(HgMediawall::PositionBelowImage);
       
  1967     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionNone);
       
  1968     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionBelowImage);
       
  1969     mMediawall->setCurrentIndex(model.index(3, 0));
       
  1970     QTest::qWait(1000);
       
  1971     QVERIFY(checkLabelAt(mWindow, expected_label_pos_below_alone, "Secondary 3"));
       
  1972 
       
  1973     mMediawall->setTitlePosition(HgMediawall::PositionAboveImage);
       
  1974     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionAboveImage);
       
  1975     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionBelowImage);
       
  1976     mMediawall->setCurrentIndex(model.index(4, 0));
       
  1977     QTest::qWait(1000);
       
  1978     QVERIFY(checkLabelAt(mWindow, expected_label_pos_above_alone, "Primary 4"));
       
  1979     QVERIFY(checkLabelAt(mWindow, expected_label_pos_below_alone, "Secondary 4"));
       
  1980 
       
  1981     mMediawall->setDescriptionPosition(HgMediawall::PositionAboveImage);
       
  1982     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionAboveImage);
       
  1983     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionAboveImage);
       
  1984     mMediawall->setCurrentIndex(model.index(5, 0));
       
  1985     QTest::qWait(1000);
       
  1986     QVERIFY(checkLabelAt(mWindow, expected_label_pos_above_top, "Primary 5"));
       
  1987     QVERIFY(checkLabelAt(mWindow, expected_label_pos_above_bottom, "Secondary 5"));
       
  1988 
       
  1989     mMediawall->setDescriptionPosition(HgMediawall::PositionNone);
       
  1990     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionAboveImage);
       
  1991     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionNone);
       
  1992     mMediawall->setCurrentIndex(model.index(6, 0));
       
  1993     QTest::qWait(1000);
       
  1994     QVERIFY(checkLabelAt(mWindow, expected_label_pos_above_alone, "Primary 6"));
       
  1995 
       
  1996     mMediawall->setTitlePosition(HgMediawall::PositionBelowImage);
       
  1997     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionBelowImage);
       
  1998     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionNone);
       
  1999     mMediawall->setCurrentIndex(model.index(7, 0));
       
  2000     QTest::qWait(1000);
       
  2001     QVERIFY(checkLabelAt(mWindow, expected_label_pos_below_alone, "Primary 7"));
       
  2002 
       
  2003     mMediawall->setDescriptionPosition(HgMediawall::PositionAboveImage);
       
  2004     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionBelowImage);
       
  2005     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionAboveImage);
       
  2006     mMediawall->setCurrentIndex(model.index(8, 0));
       
  2007     QTest::qWait(1000);
       
  2008     QVERIFY(checkLabelAt(mWindow, expected_label_pos_above_alone, "Secondary 8"));
       
  2009     QVERIFY(checkLabelAt(mWindow, expected_label_pos_below_alone, "Primary 8"));
       
  2010 
       
  2011     mMediawall->setDescriptionPosition(HgMediawall::PositionBelowImage);
       
  2012     QVERIFY(mMediawall->titlePosition() == HgMediawall::PositionBelowImage);
       
  2013     QVERIFY(mMediawall->descriptionPosition() == HgMediawall::PositionBelowImage);
       
  2014     mMediawall->setCurrentIndex(model.index(9, 0));
       
  2015     QTest::qWait(1000);
       
  2016     QVERIFY(checkLabelAt(mWindow, expected_label_pos_below_top, "Primary 9"));
       
  2017     QVERIFY(checkLabelAt(mWindow, expected_label_pos_below_bottom, "Secondary 9"));
       
  2018 
       
  2019     QTest::qWait(2000);
       
  2020 
       
  2021     delete mWindow;
       
  2022     mWindow = 0;
       
  2023 }
       
  2024 
       
  2025 void TestGanesWidgets::test_labelFontSpecsCoverFlow()
       
  2026 {
       
  2027     mWindow = new HbMainWindow;
       
  2028     mMediawall = new HgMediawall();
       
  2029 
       
  2030     TestModel model;
       
  2031     model.generateItems(50);
       
  2032     mWindow->addView(mMediawall);
       
  2033     mMediawall->setModel(&model);
       
  2034     mWindow->show();
       
  2035 
       
  2036     mMediawall->setTitleFontSpec(HbFontSpec(HbFontSpec::Primary));
       
  2037     QVERIFY(mMediawall->titleFontSpec() == HbFontSpec(HbFontSpec::Primary));
       
  2038 
       
  2039     mMediawall->setDescriptionFontSpec(HbFontSpec(HbFontSpec::Secondary));
       
  2040     QVERIFY(mMediawall->descriptionFontSpec() == HbFontSpec(HbFontSpec::Secondary));
       
  2041 
       
  2042     mMediawall->setTitleFontSpec(HbFontSpec(HbFontSpec::Title));
       
  2043     QVERIFY(mMediawall->titleFontSpec() == HbFontSpec(HbFontSpec::Title));
       
  2044 
       
  2045     mMediawall->setDescriptionFontSpec(HbFontSpec(HbFontSpec::PrimarySmall));
       
  2046     QVERIFY(mMediawall->descriptionFontSpec() == HbFontSpec(HbFontSpec::PrimarySmall));
       
  2047 
       
  2048     QTest::qWait(2000);
       
  2049 
       
  2050     delete mWindow;
       
  2051     mWindow = 0;
       
  2052 }
       
  2053 
       
  2054 void TestGanesWidgets::test_resetModelCoverFlow()
       
  2055 {
       
  2056     mWindow = new HbMainWindow;
       
  2057     mMediawall = new HgMediawall();
       
  2058 
       
  2059     TestModel model;
       
  2060     model.generateItems(50);
       
  2061     mWindow->addView(mMediawall);
       
  2062     mMediawall->setModel(&model);
       
  2063     mWindow->show();
       
  2064 
       
  2065     // Reset with same item count
       
  2066     model.reset(50);
       
  2067     QTest::qWait(2000);
       
  2068 
       
  2069     // Reset with smaller item count
       
  2070     model.reset(20);    
       
  2071     QTest::qWait(2000);
       
  2072 
       
  2073     // Reset with larger item count
       
  2074     model.reset(100);    
       
  2075     QTest::qWait(2000);
       
  2076 
       
  2077     delete mWindow;
       
  2078     mWindow = 0;
       
  2079 
       
  2080 }
       
  2081 
       
  2082 void TestGanesWidgets::test_resetModelGrid()
       
  2083 {
       
  2084     mWindow = new HbMainWindow;
       
  2085     mWidget = new HgGrid(Qt::Vertical);
       
  2086 
       
  2087     TestModel model;
       
  2088     model.generateItems(50);
       
  2089     mWindow->addView(mWidget);
       
  2090     mWidget->setModel(&model);
       
  2091     mWindow->show();
       
  2092 
       
  2093     QTest::qWait(2000);
       
  2094 
       
  2095     // Reset with same item count
       
  2096     model.reset(50);
       
  2097     QTest::qWait(2000);
       
  2098 
       
  2099     // Reset with smaller item count
       
  2100     model.reset(20);    
       
  2101     QTest::qWait(2000);
       
  2102 
       
  2103     // Reset with larger item count
       
  2104     model.reset(100);    
       
  2105     QTest::qWait(2000);
       
  2106     
       
  2107     delete mWindow;
       
  2108     mWindow = 0;
       
  2109 
       
  2110 }
       
  2111 
       
  2112 bool TestGanesWidgets::checkLabelAt(HbMainWindow *window, const QPointF &pos, const QString &expectedText)
       
  2113 {
       
  2114     HbLabel *label = findLabelAt(window->currentView(), pos);
       
  2115     if (label) {
       
  2116         if (label->plainText() == expectedText) {
       
  2117             return true;
       
  2118         }
       
  2119         else {
       
  2120             qDebug() << "Label text did not match: expected" << expectedText << "got" << label->plainText();
       
  2121             return false;
       
  2122         }
       
  2123     }
       
  2124     qDebug() << "Label not found at pos" << pos;
       
  2125     return false;
       
  2126 }
       
  2127 
       
  2128 HbLabel *TestGanesWidgets::findLabelAt(QGraphicsItem *parent, const QPointF &pos)
       
  2129 {
       
  2130     QList<QGraphicsItem *> subItems = parent->childItems();
       
  2131     int count = subItems.count();
       
  2132     for (int i = 0; i < count; i++) {
       
  2133         QGraphicsItem *item = subItems.at(i);
       
  2134         QRectF itemRect(item->pos(), item->boundingRect().size());
       
  2135         if (itemRect.contains(pos)) {
       
  2136             HbLabel *label = qgraphicsitem_cast<HbLabel *>(subItems.at(i));
       
  2137             if (label) {
       
  2138                 return label;
       
  2139             }
       
  2140             else {
       
  2141                 return findLabelAt(subItems.at(i), pos);
       
  2142             }
       
  2143         }
       
  2144     }
       
  2145     return NULL;
  1830 }
  2146 }
  1831 
  2147 
  1832 #ifdef _UNITTEST_GANESWIDGETS_LOG_TO_C_
  2148 #ifdef _UNITTEST_GANESWIDGETS_LOG_TO_C_
  1833     int main (int argc, char* argv[])
  2149     int main (int argc, char* argv[])
  1834     {
  2150     {