tst_QProgressBar: add a case for INT_MIN/INT_MAX to setValueRepaint()

Convert the function to be data-driven, then add cases for ranges with
limits INT_MIN, INT_MAX and zero to check for overflows in the
painting code. Speed up the function by removing the per-iteration
qWait() call and rely solely on the existing QTRY_VERIFY() to do the
right thing.

Change-Id: I6d2a2c2b7637fca7ddb2a9adc5f6550f8255da14
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Marc Mutz 2017-01-05 15:55:46 +01:00
parent d4ae7d39c8
commit dbfde461ed

View File

@ -45,6 +45,7 @@ private slots:
void destroyIndeterminate();
void text();
void format();
void setValueRepaint_data();
void setValueRepaint();
#ifndef Q_OS_MAC
void setMinMaxRepaint();
@ -191,21 +192,49 @@ void tst_QProgressBar::format()
QCOMPARE(bar.text(), QString());
}
void tst_QProgressBar::setValueRepaint_data()
{
QTest::addColumn<int>("min");
QTest::addColumn<int>("max");
QTest::addColumn<int>("increment");
auto add = [](int min, int max, int increment) {
QTest::addRow("%d-%d@%d", min, max, increment) << min << max << increment;
};
add(0, 10, 1);
auto add_set = [=](int min, int max, int increment) {
// check corner cases, and adjacent values (to circumvent explicit checks for corner cases)
add(min, max, increment);
add(min + 1, max, increment);
add(min, max - 1, increment);
add(min + 1, max - 1, increment);
};
add_set(INT_MIN, INT_MAX, INT_MAX / 50 + 1);
add_set(0, INT_MAX, INT_MAX / 100 + 1);
add_set(INT_MIN, 0, INT_MAX / 100 + 1);
}
void tst_QProgressBar::setValueRepaint()
{
QFETCH(int, min);
QFETCH(int, max);
QFETCH(int, increment);
ProgressBar pbar;
pbar.setMinimum(0);
pbar.setMaximum(10);
pbar.setMinimum(min);
pbar.setMaximum(max);
pbar.setFormat("%v");
pbar.move(300, 300);
pbar.show();
QVERIFY(QTest::qWaitForWindowExposed(&pbar));
QApplication::processEvents();
for (int i = pbar.minimum(); i < pbar.maximum(); ++i) {
for (qint64 i = min; i < max; i += increment) {
pbar.repainted = false;
pbar.setValue(i);
QTest::qWait(50);
pbar.setValue(int(i));
QTRY_VERIFY(pbar.repainted);
}
}