diff options
author | Axel Spoerl <Axel.Spoerl@qt.io> | 2022-01-06 15:38:43 +0100 |
---|---|---|
committer | Axel Spoerl <Axel.Spoerl@qt.io> | 2022-01-08 07:43:40 +0100 |
commit | 12c56aa43a7c48f7f34e75c3a7fb1603102f1af5 (patch) | |
tree | 94372516691f1df5c844ade11349b49b3f6d6e79 /tests | |
parent | 000f8b8c0b51e016ddd5c06068538fc7cdfce326 (diff) |
Turn QLabel wordWrap unit test into data driven test
Add test to verify that allowing wordWrap actually breaks long lines.
Pick-to: 6.3
Change-Id: I09bd2d754e86ebf35db551ee76f7f037371acec9
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp index 7e5b5e7c58..1af61e9ec6 100644 --- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp +++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp @@ -38,6 +38,7 @@ #include <qmovie.h> #include <qpicture.h> #include <qmessagebox.h> +#include <qsizepolicy.h> #include <qfontmetrics.h> #include <qmath.h> #include <private/qlabel_p.h> @@ -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<QString>("text"); + + QTest::newRow("Plain text") << "Plain text1"; + QTest::newRow("Rich text") << "<b>Rich text</b>"; + 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() { - QLabel label; + 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("<b>rich text</b>"); - 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("<b>rich text</b>"); - QVERIFY(!label.wordWrap()); } void tst_QLabel::eventPropagation_data() |