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>
This commit is contained in:
parent
000f8b8c0b
commit
12c56aa43a
@ -38,6 +38,7 @@
|
|||||||
#include <qmovie.h>
|
#include <qmovie.h>
|
||||||
#include <qpicture.h>
|
#include <qpicture.h>
|
||||||
#include <qmessagebox.h>
|
#include <qmessagebox.h>
|
||||||
|
#include <qsizepolicy.h>
|
||||||
#include <qfontmetrics.h>
|
#include <qfontmetrics.h>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
#include <private/qlabel_p.h>
|
#include <private/qlabel_p.h>
|
||||||
@ -75,6 +76,7 @@ private Q_SLOTS:
|
|||||||
#endif
|
#endif
|
||||||
void setNum();
|
void setNum();
|
||||||
void clear();
|
void clear();
|
||||||
|
void wordWrap_data();
|
||||||
void wordWrap();
|
void wordWrap();
|
||||||
void eventPropagation_data();
|
void eventPropagation_data();
|
||||||
void eventPropagation();
|
void eventPropagation();
|
||||||
@ -268,21 +270,36 @@ void tst_QLabel::clear()
|
|||||||
QVERIFY(testWidget->text().isEmpty());
|
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()
|
void tst_QLabel::wordWrap()
|
||||||
{
|
{
|
||||||
|
QFETCH(QString, text);
|
||||||
|
|
||||||
QLabel label;
|
QLabel label;
|
||||||
|
label.setText(text);
|
||||||
QVERIFY(!label.wordWrap());
|
QVERIFY(!label.wordWrap());
|
||||||
|
QVERIFY(!label.sizePolicy().hasHeightForWidth());
|
||||||
|
|
||||||
label.setText("Plain Text");
|
const QSize unWrappedSizeHint = label.sizeHint();
|
||||||
QVERIFY(!label.wordWrap());
|
|
||||||
|
|
||||||
label.setText("<b>rich text</b>");
|
label.setWordWrap(true);
|
||||||
QVERIFY(!label.wordWrap());
|
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()
|
void tst_QLabel::eventPropagation_data()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user