summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2012-08-16 09:55:50 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-23 23:31:10 +0200
commit4d5f3cf6275df46e8ebe262026a392a8154cf36a (patch)
tree510598f552ca10c836789f02b0db8f5d35f9ad5b /tests
parentb1e082ec9f4ec0a603f69e280fe2c5438c67a09e (diff)
Test for quadratic behaviour when rendering long line in QTextEdit
QTextEdit showing long lines using lots of text format (for example with a syntax highlighter) used to expose a quadratic behaviour which make it impossible to edit files with long lines. It was fiexed in the few previous commit Task-number: QTBUG-8389 Change-Id: Ib7203497a7699a85ae1dfb70fe65d5fb36884b58 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
index 846bb41181..7d6428211f 100644
--- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
+++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
@@ -62,6 +62,7 @@
#include <qabstracttextdocumentlayout.h>
#include <qtextdocumentfragment.h>
+#include <qsyntaxhighlighter.h>
#include "../../../shared/platforminputcontext.h"
#include <private/qinputmethod_p.h>
@@ -212,6 +213,8 @@ private slots:
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
+ void highlightLongLine();
+
private:
void createSelection();
int blockCount() const;
@@ -2483,5 +2486,38 @@ void tst_QTextEdit::inputMethodQueryImHints()
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
}
+void tst_QTextEdit::highlightLongLine()
+{
+ QTextEdit edit;
+ edit.setAcceptRichText(false);
+ edit.setWordWrapMode(QTextOption::NoWrap);
+
+ QString singeLongLine;
+ for (int i = 0; i < 10000; ++i)
+ singeLongLine += "0123456789";
+ edit.setPlainText(singeLongLine);
+
+ class NumHighlighter : public QSyntaxHighlighter {
+ public:
+ explicit NumHighlighter(QTextDocument*doc) : QSyntaxHighlighter(doc) {};
+ virtual void highlightBlock(const QString& text) {
+ // odd number in bold
+ QTextCharFormat format;
+ format.setFontWeight(QFont::Bold);
+ for (int i = 0; i < text.size(); ++i) {
+ if (text.at(i).unicode() % 2)
+ setFormat(i, 1, format);
+ }
+ }
+ };
+ NumHighlighter nh(edit.document());
+ edit.show();
+ QTest::qWaitForWindowActive(edit.windowHandle());
+ QCoreApplication::processEvents();
+ //If there is a quadratic behaviour, this would take forever.
+ QVERIFY(true);
+}
+
+
QTEST_MAIN(tst_QTextEdit)
#include "tst_qtextedit.moc"