|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
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 |
|
14 ** this package. |
|
15 ** |
|
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. |
|
23 ** |
|
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. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <qtest.h> |
|
42 #include <QtTest/QtTest> |
|
43 #include <QtGui/QTextLayout> |
|
44 #include <private/qdeclarativestyledtext_p.h> |
|
45 |
|
46 class tst_qdeclarativestyledtext : public QObject |
|
47 { |
|
48 Q_OBJECT |
|
49 public: |
|
50 tst_qdeclarativestyledtext() |
|
51 { |
|
52 } |
|
53 |
|
54 private slots: |
|
55 void textOutput(); |
|
56 void textOutput_data(); |
|
57 }; |
|
58 |
|
59 // For malformed input all we test is that we get the expected text out. |
|
60 // |
|
61 void tst_qdeclarativestyledtext::textOutput_data() |
|
62 { |
|
63 QTest::addColumn<QString>("input"); |
|
64 QTest::addColumn<QString>("output"); |
|
65 |
|
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") << "" << ""; |
|
85 } |
|
86 |
|
87 void tst_qdeclarativestyledtext::textOutput() |
|
88 { |
|
89 QFETCH(QString, input); |
|
90 QFETCH(QString, output); |
|
91 |
|
92 QTextLayout layout; |
|
93 QDeclarativeStyledText::parse(input, layout); |
|
94 |
|
95 QCOMPARE(layout.text(), output); |
|
96 } |
|
97 |
|
98 |
|
99 QTEST_MAIN(tst_qdeclarativestyledtext) |
|
100 |
|
101 #include "tst_qdeclarativestyledtext.moc" |