From efc475a996574364046335e2d66c4a091c5ccc31 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 18 Oct 2012 13:36:02 +0200 Subject: Fix integer overflow in QSpinBox. Change-Id: Ic204d42fbdffc44576f7e76132bc53621e836299 Reviewed-by: Marc Mutz --- .../auto/widgets/widgets/qspinbox/tst_qspinbox.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/auto/widgets/widgets') diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index beea5f3052..6e1abb9fa9 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -135,6 +135,8 @@ private slots: void sizeHint(); + void integerOverflow(); + void taskQTBUG_5008_textFromValueAndValidate(); public slots: @@ -1014,6 +1016,35 @@ void tst_QSpinBox::taskQTBUG_5008_textFromValueAndValidate() QCOMPARE(spinbox.text(), spinbox.locale().toString(spinbox.value())); } +void tst_QSpinBox::integerOverflow() +{ + QSpinBox sb; + sb.setRange(INT_MIN, INT_MAX); + + sb.setValue(INT_MAX - 1); + sb.stepUp(); + QCOMPARE(sb.value(), INT_MAX); + sb.stepUp(); + QCOMPARE(sb.value(), INT_MAX); + + sb.setValue(INT_MIN + 1); + sb.stepDown(); + QCOMPARE(sb.value(), INT_MIN); + sb.stepDown(); + QCOMPARE(sb.value(), INT_MIN); + + sb.setValue(0); + QCOMPARE(sb.value(), 0); + sb.setSingleStep(INT_MAX); + sb.stepUp(); + QCOMPARE(sb.value(), INT_MAX); + sb.stepDown(); + QCOMPARE(sb.value(), 0); + sb.stepDown(); + QCOMPARE(sb.value(), INT_MIN + 1); + sb.stepDown(); + QCOMPARE(sb.value(), INT_MIN); +} QTEST_MAIN(tst_QSpinBox) #include "tst_qspinbox.moc" -- cgit v1.2.3