diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp index 7e5b5e7c58a..1af61e9ec69 100644 --- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp +++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,7 @@ private Q_SLOTS: #endif void setNum(); void clear(); + void wordWrap_data(); void wordWrap(); void eventPropagation_data(); void eventPropagation(); @@ -268,21 +270,36 @@ void tst_QLabel::clear() QVERIFY(testWidget->text().isEmpty()); } +void tst_QLabel::wordWrap_data() +{ + QTest::addColumn("text"); + + QTest::newRow("Plain text") << "Plain text1"; + QTest::newRow("Rich text") << "Rich text"; + QTest::newRow("Long text") + << "This is a very long text to check that QLabel " + "does not wrap, even if the text would require wrapping to be fully displayed"; +} + void tst_QLabel::wordWrap() { + QFETCH(QString, text); + QLabel label; - + label.setText(text); QVERIFY(!label.wordWrap()); + QVERIFY(!label.sizePolicy().hasHeightForWidth()); - label.setText("Plain Text"); - QVERIFY(!label.wordWrap()); + const QSize unWrappedSizeHint = label.sizeHint(); - label.setText("rich text"); - QVERIFY(!label.wordWrap()); + label.setWordWrap(true); + QVERIFY(label.sizePolicy().hasHeightForWidth()); + + if (text.size() > 1 && text.contains(" ")) { + const int wrappedHeight = label.heightForWidth(unWrappedSizeHint.width() / 2); + QVERIFY(wrappedHeight > unWrappedSizeHint.height()); + } - label.setWordWrap(false); - label.setText("rich text"); - QVERIFY(!label.wordWrap()); } void tst_QLabel::eventPropagation_data()