summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKevin Funk <kfunk@kde.org>2014-08-28 15:46:03 +0200
committerKevin Funk <kevin.funk@kdab.com>2014-09-02 14:18:08 +0200
commiteb447679456336d387bb69a56c164b06fbe83166 (patch)
tree6bc3edc6700f126d751a4dedb77cc5b0b9d30a73 /tests
parentb9a7cedb6ebd85f249f54c8688943346c7a98260 (diff)
Fix crash in QTextLayout::cursorToX
When 'cursorPos' is out of bounds ([0, lineEnd]), this method crashed. Change-Id: Ia0540ab3afbffb5c598f7b8515263cce3b3928e4 Task-number: QTBUG-40753 Reviewed-by: Dominik Haumann <dhaumann@kde.org> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
index ec698e5db4..e49d8c3b07 100644
--- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
+++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
@@ -86,6 +86,7 @@ private slots:
void cursorToXForSetColumns();
void cursorToXForTrailingSpaces_data();
void cursorToXForTrailingSpaces();
+ void cursorToXInvalidInput();
void horizontalAlignment_data();
void horizontalAlignment();
void horizontalAlignmentMultiline_data();
@@ -674,6 +675,28 @@ void tst_QTextLayout::cursorToXForTrailingSpaces()
QCOMPARE(line.cursorToX(6), cursorAt6);
}
+void tst_QTextLayout::cursorToXInvalidInput()
+{
+ QTextLayout layout("aaa", testFont);
+
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ line.setLineWidth(5);
+ layout.endLayout();
+
+ int cursorPos;
+
+ cursorPos = 0;
+ layout.lineAt(0).cursorToX(&cursorPos);
+ QCOMPARE(cursorPos, 0);
+ cursorPos = -300;
+ layout.lineAt(0).cursorToX(&cursorPos);
+ QCOMPARE(cursorPos, 0);
+ cursorPos = 300;
+ layout.lineAt(0).cursorToX(&cursorPos);
+ QCOMPARE(cursorPos, 3);
+}
+
void tst_QTextLayout::horizontalAlignment_data()
{
qreal width = TESTFONT_SIZE * 4;