summaryrefslogtreecommitdiffstats
path: root/tests/auto/qspinbox
diff options
context:
space:
mode:
authorjasplin <qt-info@nokia.com>2009-06-24 06:51:26 (GMT)
committerjasplin <qt-info@nokia.com>2009-06-24 06:55:57 (GMT)
commit84b5bd06dcc7c51d5b13f340aafd9797e1722c2e (patch)
tree1ceb11cf6b16da1f98270023e5448942014d3f22 /tests/auto/qspinbox
parentaca09d2b5038ed193d198f4097b17051f5f94116 (diff)
downloadQt-84b5bd06dcc7c51d5b13f340aafd9797e1722c2e.zip
Qt-84b5bd06dcc7c51d5b13f340aafd9797e1722c2e.tar.gz
Qt-84b5bd06dcc7c51d5b13f340aafd9797e1722c2e.tar.bz2
Fixed sizeHint update bug in QSpinBox.
QSpinBox failed to recalculate its cached size hint when setting the range, prefix, or suffix. Reviewed-by: janarve Task-number: 255051
Diffstat (limited to 'tests/auto/qspinbox')
-rw-r--r--tests/auto/qspinbox/tst_qspinbox.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/qspinbox/tst_qspinbox.cpp b/tests/auto/qspinbox/tst_qspinbox.cpp
index d161c85..ec1dced 100644
--- a/tests/auto/qspinbox/tst_qspinbox.cpp
+++ b/tests/auto/qspinbox/tst_qspinbox.cpp
@@ -65,6 +65,7 @@
#include <QDoubleSpinBox>
#include <QVBoxLayout>
#include <QKeySequence>
+#include <QStackedWidget>
#include <QDebug>
#include "../../shared/util.h"
@@ -142,6 +143,9 @@ private slots:
void specialValue();
void textFromValue();
+
+ void sizeHint();
+
public slots:
void valueChangedHelper(const QString &);
void valueChangedHelper(int);
@@ -956,5 +960,80 @@ void tst_QSpinBox::textFromValue()
QCOMPARE(spinBox.textFromValue(INT_MIN), QString::number(INT_MIN));
}
+class sizeHint_Tester
+{
+ 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)
+ {
+ spinBox->setSuffix("abcdefghij");
+ }
+};
+
+void tst_QSpinBox::sizeHint()
+{
+ sizeHint_setRangeTester setRangeTester;
+ setRangeTester.exec();
+ QCOMPARE(setRangeTester.size1, setRangeTester.size2);
+
+ sizeHint_setPrefixTester setPrefixTester;
+ setPrefixTester.exec();
+ QCOMPARE(setPrefixTester.size1, setPrefixTester.size2);
+
+ sizeHint_setSuffixTester setSuffixTester;
+ setSuffixTester.exec();
+ QCOMPARE(setSuffixTester.size1, setSuffixTester.size2);
+}
+
QTEST_MAIN(tst_QSpinBox)
#include "tst_qspinbox.moc"