Auto test for passing QTextEdit as QSyntaxHighlighter parent

Change-Id: Ia225723de5b0b2085a72a2af26e2a563b65955d8
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
J-P Nurmi 2012-08-17 10:52:54 +02:00 committed by Qt by Nokia
parent 468c22f673
commit fd234c2fc6
2 changed files with 20 additions and 1 deletions

View File

@ -3,4 +3,5 @@ CONFIG += parallel_test
TARGET = tst_qsyntaxhighlighter
SOURCES += tst_qsyntaxhighlighter.cpp
QT += testlib
!contains(QT_CONFIG, no-widgets) QT += widgets
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0

View File

@ -47,6 +47,10 @@
#include <QAbstractTextDocumentLayout>
#include <QSyntaxHighlighter>
#ifndef QT_NO_WIDGETS
#include <QTextEdit>
#endif
class QTestDocumentLayout : public QAbstractTextDocumentLayout
{
Q_OBJECT
@ -97,7 +101,10 @@ private slots:
void noContentsChangedDuringHighlight();
void rehighlight();
void rehighlightBlock();
#ifndef QT_NO_WIDGETS
void textEditParent();
#endif
private:
QTextDocument *doc;
QTestDocumentLayout *lout;
@ -123,6 +130,8 @@ class TestHighlighter : public QSyntaxHighlighter
public:
inline TestHighlighter(const QList<QTextLayout::FormatRange> &fmts, QTextDocument *parent)
: QSyntaxHighlighter(parent), formats(fmts), highlighted(false), callCount(0) {}
inline TestHighlighter(QObject *parent)
: QSyntaxHighlighter(parent) {}
inline TestHighlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent), highlighted(false), callCount(0) {}
@ -542,5 +551,14 @@ void tst_QSyntaxHighlighter::rehighlightBlock()
QCOMPARE(hl->callCount, 1);
}
#ifndef QT_NO_WIDGETS
void tst_QSyntaxHighlighter::textEditParent()
{
QTextEdit textEdit;
TestHighlighter *hl = new TestHighlighter(&textEdit);
QCOMPARE(hl->document(), textEdit.document());
}
#endif
QTEST_MAIN(tst_QSyntaxHighlighter)
#include "tst_qsyntaxhighlighter.moc"