Stabilize tst_QListView::batchedMode().
The test showed failures on OS X:
FAIL! : tst_QListView::batchedMode() Compared values are not the same
Actual (ba.size()): 2
Expected (3) : 3
Loc: [tst_qlistview.cpp(848)]
Use QTRY_COMPARE() to count the number of visible indexes with
a helper function instead of using hard-coded timeouts. Item 3
appears with a little delay on OS X.
Change-Id: I2fb2ff5ebdf9dbe85bdc79401375ad6f47b7b12b
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
bb10
parent
2dbe90c248
commit
d6553d2cd8
|
|
@ -304,6 +304,7 @@ void tst_QListView::init()
|
|||
|
||||
void tst_QListView::cleanup()
|
||||
{
|
||||
QVERIFY(QApplication::topLevelWidgets().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -789,14 +790,31 @@ void tst_QListView::hideFirstRow()
|
|||
QTest::qWait(10);
|
||||
}
|
||||
|
||||
static int modelIndexCount(const QAbstractItemView *view)
|
||||
{
|
||||
QBitArray ba;
|
||||
for (int y = 0, height = view->height(); y < height; ++y) {
|
||||
const QModelIndex idx = view->indexAt( QPoint(1, y) );
|
||||
if (!idx.isValid())
|
||||
break;
|
||||
if (idx.row() >= ba.size())
|
||||
ba.resize(idx.row() + 1);
|
||||
ba.setBit(idx.row(), true);
|
||||
}
|
||||
return ba.size();
|
||||
}
|
||||
|
||||
void tst_QListView::batchedMode()
|
||||
{
|
||||
const int rowCount = 3;
|
||||
|
||||
QStringList items;
|
||||
for (int i=0; i <3; ++i)
|
||||
items << "item";
|
||||
for (int i = 0; i < rowCount; ++i)
|
||||
items << QLatin1String("item ") + QString::number(i);
|
||||
QStringListModel model(items);
|
||||
|
||||
QListView view;
|
||||
view.setWindowTitle(QTest::currentTestFunction());
|
||||
view.setModel(&model);
|
||||
view.setUniformItemSizes(true);
|
||||
view.setViewMode(QListView::ListMode);
|
||||
|
|
@ -805,22 +823,8 @@ void tst_QListView::batchedMode()
|
|||
view.resize(200,400);
|
||||
view.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||
QTest::qWait(100);
|
||||
|
||||
#if defined(Q_OS_WINCE)
|
||||
QTest::qWait(2000);
|
||||
#endif
|
||||
QBitArray ba;
|
||||
for (int y = 0; y < view.height(); ++y) {
|
||||
QModelIndex idx = view.indexAt( QPoint(1, y) );
|
||||
if (!idx.isValid())
|
||||
break;
|
||||
if (idx.row() >= ba.size())
|
||||
ba.resize(idx.row() + 1);
|
||||
ba.setBit(idx.row(), true);
|
||||
}
|
||||
QCOMPARE(ba.size(), 3);
|
||||
|
||||
QTRY_COMPARE(modelIndexCount(&view), rowCount);
|
||||
|
||||
// Test the dynamic listview too.
|
||||
view.setViewMode(QListView::IconMode);
|
||||
|
|
@ -828,22 +832,7 @@ void tst_QListView::batchedMode()
|
|||
view.setFlow(QListView::TopToBottom);
|
||||
view.setBatchSize(2);
|
||||
|
||||
#if !defined(Q_OS_WINCE)
|
||||
QTest::qWait(100);
|
||||
#else
|
||||
QTest::qWait(2000);
|
||||
#endif
|
||||
|
||||
ba.clear();
|
||||
for (int y = 0; y < view.height(); ++y) {
|
||||
QModelIndex idx = view.indexAt( QPoint(1, y) );
|
||||
if (!idx.isValid())
|
||||
break;
|
||||
if (idx.row() >= ba.size())
|
||||
ba.resize(idx.row() + 1);
|
||||
ba.setBit(idx.row(), true);
|
||||
}
|
||||
QCOMPARE(ba.size(), 3);
|
||||
QTRY_COMPARE(modelIndexCount(&view), rowCount);
|
||||
}
|
||||
|
||||
void tst_QListView::setCurrentIndex()
|
||||
|
|
|
|||
Loading…
Reference in New Issue