diff options
author | jasplin <qt-info@nokia.com> | 2009-06-24 08:29:00 (GMT) |
---|---|---|
committer | jasplin <qt-info@nokia.com> | 2009-06-24 08:31:54 (GMT) |
commit | 0068e3e0ffa1948f95a4d96d514e0e8b08624dae (patch) | |
tree | 9a62910d72be4ec91549ce45a8671f276e5c42d4 /tests/auto/qspinbox | |
parent | cfcbd3f694169437894e711d33d8fb183316be16 (diff) | |
download | Qt-0068e3e0ffa1948f95a4d96d514e0e8b08624dae.zip Qt-0068e3e0ffa1948f95a4d96d514e0e8b08624dae.tar.gz Qt-0068e3e0ffa1948f95a4d96d514e0e8b08624dae.tar.bz2 |
Simplified the tst_QSpinBox::sizeHint() autotest.
Suggested by Jan Arve.
Reviewed-by: TrustMe
Diffstat (limited to 'tests/auto/qspinbox')
-rw-r--r-- | tests/auto/qspinbox/tst_qspinbox.cpp | 91 |
1 files changed, 28 insertions, 63 deletions
diff --git a/tests/auto/qspinbox/tst_qspinbox.cpp b/tests/auto/qspinbox/tst_qspinbox.cpp index ec1dced..a3b7979 100644 --- a/tests/auto/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/qspinbox/tst_qspinbox.cpp @@ -960,79 +960,44 @@ void tst_QSpinBox::textFromValue() QCOMPARE(spinBox.textFromValue(INT_MIN), QString::number(INT_MIN)); } -class sizeHint_Tester +class sizeHint_SpinBox : public QSpinBox { - QSize createStackedWidget(bool delaySpinBoxOperation) - { - QWidget *widget = new QWidget; - QHBoxLayout *layout = new QHBoxLayout(widget); - QSpinBox *spinBox = new QSpinBox; - if (!delaySpinBoxOperation) - spinBoxOperation(spinBox); - layout->addWidget(spinBox); - layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); - QStackedWidget *stackedWidget = new QStackedWidget; - stackedWidget->addWidget(widget); - if (delaySpinBoxOperation) - spinBoxOperation(spinBox); - - stackedWidget->resize(500, 30); - stackedWidget->show(); - QTest::qWait(100); - - return spinBox->size(); - } - virtual void spinBoxOperation(QSpinBox *) = 0; public: - QSize size1; - QSize size2; - void exec() - { - size1 = createStackedWidget(true); - size2 = createStackedWidget(false); - } - sizeHint_Tester() : size1(1, 0), size2(2, 0) {} - virtual ~sizeHint_Tester() {} -}; - -class sizeHint_setRangeTester : public sizeHint_Tester -{ - void spinBoxOperation(QSpinBox *spinBox) - { - spinBox->setRange(0, 1234567890); - spinBox->setValue(spinBox->maximum()); - } -}; - -class sizeHint_setPrefixTester : public sizeHint_Tester -{ - void spinBoxOperation(QSpinBox *spinBox) - { - spinBox->setPrefix("abcdefghij"); - } -}; - -class sizeHint_setSuffixTester : public sizeHint_Tester -{ - void spinBoxOperation(QSpinBox *spinBox) + QSize sizeHint() const { - spinBox->setSuffix("abcdefghij"); + ++sizeHintRequests; + return QSpinBox::sizeHint(); } + mutable int sizeHintRequests; }; void tst_QSpinBox::sizeHint() { - sizeHint_setRangeTester setRangeTester; - setRangeTester.exec(); - QCOMPARE(setRangeTester.size1, setRangeTester.size2); + QWidget *widget = new QWidget; + QHBoxLayout *layout = new QHBoxLayout(widget); + sizeHint_SpinBox *spinBox = new sizeHint_SpinBox; + layout->addWidget(spinBox); + widget->show(); + QTest::qWait(100); - sizeHint_setPrefixTester setPrefixTester; - setPrefixTester.exec(); - QCOMPARE(setPrefixTester.size1, setPrefixTester.size2); + // Prefix + spinBox->sizeHintRequests = 0; + spinBox->setPrefix(QLatin1String("abcdefghij")); + QTest::qWait(100); + QVERIFY(spinBox->sizeHintRequests > 0); - sizeHint_setSuffixTester setSuffixTester; - setSuffixTester.exec(); - QCOMPARE(setSuffixTester.size1, setSuffixTester.size2); + // Suffix + spinBox->sizeHintRequests = 0; + spinBox->setSuffix(QLatin1String("abcdefghij")); + QTest::qWait(100); + QVERIFY(spinBox->sizeHintRequests > 0); + + // Range + spinBox->sizeHintRequests = 0; + spinBox->setRange(0, 1234567890); + spinBox->setValue(spinBox->maximum()); + QTest::qWait(100); + QVERIFY(spinBox->sizeHintRequests > 0); } QTEST_MAIN(tst_QSpinBox) |