1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include <QtTest/QtTest>
43 #include <QtGui/QTextLayout>
44 #include <private/qdeclarativestyledtext_p.h>
46 class tst_qdeclarativestyledtext : public QObject
50 tst_qdeclarativestyledtext()
56 void textOutput_data();
59 // For malformed input all we test is that we get the expected text out.
61 void tst_qdeclarativestyledtext::textOutput_data()
63 QTest::addColumn<QString>("input");
64 QTest::addColumn<QString>("output");
66 QTest::newRow("bold") << "<b>bold</b>" << "bold";
67 QTest::newRow("italic") << "<b>italic</b>" << "italic";
68 QTest::newRow("missing >") << "<b>text</b" << "text";
69 QTest::newRow("missing b>") << "<b>text</" << "text";
70 QTest::newRow("missing /b>") << "<b>text<" << "text";
71 QTest::newRow("missing </b>") << "<b>text" << "text";
72 QTest::newRow("bad nest") << "<b>text <i>italic</b></i>" << "text italic";
73 QTest::newRow("font color") << "<font color=\"red\">red text</font>" << "red text";
74 QTest::newRow("font color: single quote") << "<font color='red'>red text</font>" << "red text";
75 QTest::newRow("font size") << "<font size=\"1\">text</font>" << "text";
76 QTest::newRow("font empty") << "<font>text</font>" << "text";
77 QTest::newRow("font bad 1") << "<font ezis=\"blah\">text</font>" << "text";
78 QTest::newRow("font bad 2") << "<font size=\"1>text</font>" << "";
79 QTest::newRow("extra close") << "<b>text</b></b>" << "text";
80 QTest::newRow("extra space") << "<b >text</b>" << "text";
81 QTest::newRow("entities") << "<b>this & that</b>" << "<b>this & that</b>";
82 QTest::newRow("newline") << "text<br>more text" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") ;
83 QTest::newRow("self-closing newline") << "text<br/>more text" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") ;
84 QTest::newRow("empty") << "" << "";
87 void tst_qdeclarativestyledtext::textOutput()
89 QFETCH(QString, input);
90 QFETCH(QString, output);
93 QDeclarativeStyledText::parse(input, layout);
95 QCOMPARE(layout.text(), output);
99 QTEST_MAIN(tst_qdeclarativestyledtext)
101 #include "tst_qdeclarativestyledtext.moc"