diff options
Diffstat (limited to 'tests/auto/gui/text')
15 files changed, 674 insertions, 341 deletions
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index aa5fa10a33..a7248869ed 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -316,25 +316,25 @@ void tst_QFont::italicOblique() QStringList::ConstIterator f_it, f_end = families.end(); for (f_it = families.begin(); f_it != f_end; ++f_it) { - QString family = *f_it; - QStringList styles = fdb.styles(family); - QVERIFY(!styles.isEmpty()); - QStringList::ConstIterator s_it, s_end = styles.end(); - for (s_it = styles.begin(); s_it != s_end; ++s_it) { - QString style = *s_it; - - if (fdb.isSmoothlyScalable(family, style)) { - if (style.contains("Oblique")) { - style.replace("Oblique", "Italic"); - } else if (style.contains("Italic")) { - style.replace("Italic", "Oblique"); - } else { - continue; - } - QFont f = fdb.font(family, style, 12); - QVERIFY(f.italic()); - } - } + QString family = *f_it; + QStringList styles = fdb.styles(family); + QVERIFY(!styles.isEmpty()); + QStringList::ConstIterator s_it, s_end = styles.end(); + for (s_it = styles.begin(); s_it != s_end; ++s_it) { + QString style = *s_it; + + if (fdb.isSmoothlyScalable(family, style)) { + if (style.contains("Oblique")) { + style.replace("Oblique", "Italic"); + } else if (style.contains("Italic")) { + style.replace("Italic", "Oblique"); + } else { + continue; + } + QFont f = fdb.font(family, style, 12); + QVERIFY(f.italic()); + } + } } } @@ -342,16 +342,16 @@ void tst_QFont::compare() { QFont font; { - QFont font2 = font; - font2.setPointSize( 24 ); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); + QFont font2 = font; + font2.setPointSize(24); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); } { - QFont font2 = font; - font2.setPixelSize( 24 ); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); + QFont font2 = font; + font2.setPixelSize(24); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); } font.setPointSize(12); @@ -361,69 +361,69 @@ void tst_QFont::compare() font.setStrikeOut(false); font.setOverline(false); { - QFont font2 = font; - font2.setPointSize( 24 ); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); + QFont font2 = font; + font2.setPointSize(24); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); } { - QFont font2 = font; - font2.setPixelSize( 24 ); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); + QFont font2 = font; + font2.setPixelSize(24); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); } { - QFont font2 = font; - - font2.setItalic(true); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); - font2.setItalic(false); - QVERIFY( font == font2 ); - QVERIFY(!(font < font2)); - - font2.setWeight(QFont::Bold); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); - font2.setWeight(QFont::Normal); - QVERIFY( font == font2 ); - QVERIFY(!(font < font2)); - - font.setUnderline(true); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); - font.setUnderline(false); - QVERIFY( font == font2 ); - QVERIFY(!(font < font2)); - - font.setStrikeOut(true); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); - font.setStrikeOut(false); - QVERIFY( font == font2 ); - QVERIFY(!(font < font2)); - - font.setOverline(true); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); - font.setOverline(false); - QVERIFY( font == font2 ); - QVERIFY(!(font < font2)); + QFont font2 = font; + + font2.setItalic(true); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); + font2.setItalic(false); + QVERIFY(font == font2); + QVERIFY(!(font < font2)); + + font2.setWeight(QFont::Bold); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); + font2.setWeight(QFont::Normal); + QVERIFY(font == font2); + QVERIFY(!(font < font2)); + + font.setUnderline(true); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); + font.setUnderline(false); + QVERIFY(font == font2); + QVERIFY(!(font < font2)); + + font.setStrikeOut(true); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); + font.setStrikeOut(false); + QVERIFY(font == font2); + QVERIFY(!(font < font2)); + + font.setOverline(true); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); + font.setOverline(false); + QVERIFY(font == font2); + QVERIFY(!(font < font2)); font.setCapitalization(QFont::SmallCaps); - QVERIFY( font != font2 ); - QCOMPARE(font < font2,!(font2 < font)); + QVERIFY(font != font2); + QCOMPARE(font < font2,!(font2 < font)); font.setCapitalization(QFont::MixedCase); - QVERIFY( font == font2 ); - QVERIFY(!(font < font2)); + QVERIFY(font == font2); + QVERIFY(!(font < font2)); } #if defined(Q_WS_X11) { - QFont font1, font2; - font1.setRawName("-Adobe-Helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"); - font2.setRawName("-Adobe-Helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1"); - QVERIFY(font1 != font2); + QFont font1, font2; + font1.setRawName("-Adobe-Helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"); + font2.setRawName("-Adobe-Helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1"); + QVERIFY(font1 != font2); } #endif } diff --git a/tests/auto/gui/text/qfontdatabase/FreeMono.ttf b/tests/auto/gui/text/qfontdatabase/FreeMono.ttf Binary files differdeleted file mode 100644 index d7ce52ddc7..0000000000 --- a/tests/auto/gui/text/qfontdatabase/FreeMono.ttf +++ /dev/null diff --git a/tests/auto/gui/text/qfontdatabase/LED_REAL.TTF b/tests/auto/gui/text/qfontdatabase/LED_REAL.TTF Binary files differnew file mode 100644 index 0000000000..f87ea95e0e --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/LED_REAL.TTF diff --git a/tests/auto/gui/text/qfontdatabase/LED_REAL_readme.txt b/tests/auto/gui/text/qfontdatabase/LED_REAL_readme.txt new file mode 100644 index 0000000000..06a5b40313 --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/LED_REAL_readme.txt @@ -0,0 +1,34 @@ +Font: LED Real (led_real.ttf) +Created By: Matthew Welch +E-Mail: daffy-duck@worldnet.att.net +Web Address: http://home.att.net/~daffy-duck + (PGP public key available here) + +LED Real, like all of my fonts, is free. You can use it for most +personal or business uses you'd like, and I ask for no money. I +would, however, like to hear from you. If you use my fonts for +something please send me a postcard or e-mail letting me know how +you used it. Send me a copy if you can or let me know where I can +find your work. + +You may use this font for graphical or printed work, but you may not +sell it or include it in a collection of fonts (on CD or otherwise) +being sold. You can redistribute this font as long as you charge +nothing to receive it. If you redistribute it include this text file +with it as is (without modifications). + +If you use this font for commercial purposes please credit me in +at least some little way. + +About the font: + +Unlike most LED/LCD style fonts mine could be recreated with an +actual LED. I created this font working from memories of the good +old Speak and Spell display. Since I don't have an actual Speak +and Spell to work from I had to just do as well as I could in its +spirit. Be warned that some characters look just like others. The +( and the <, for instance. Also C and [. Most of these will be +pretty clear in context. To see all the sections of the LED "lit +up" at once use character 127 (hold down alt and type 0127 on the +numeric keypad). This font is, of course, monospaced. + diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index 104d3465f2..28db0ba291 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -83,7 +83,7 @@ private: }; tst_QFontDatabase::tst_QFontDatabase() - : m_testFont(QFINDTESTDATA("FreeMono.ttf")) + : m_testFont(QFINDTESTDATA("LED_REAL.TTF")) { } @@ -124,11 +124,11 @@ void tst_QFontDatabase::styles() QStringList styles = fdb.styles( font ); QStringList::Iterator it = styles.begin(); while ( it != styles.end() ) { - QString style = *it; - QString trimmed = style.trimmed(); - ++it; + QString style = *it; + QString trimmed = style.trimmed(); + ++it; - QCOMPARE( style, trimmed ); + QCOMPARE(style, trimmed); } } @@ -160,7 +160,7 @@ void tst_QFontDatabase::fixedPitch() QFontDatabase fdb; if (!fdb.families().contains(font)) - QSKIP( "Font not installed"); + QSKIP("Font not installed"); QCOMPARE(fdb.isFixedPitch(font), fixedPitch); diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index cddec5b6e7..7adaac9fac 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -163,7 +163,7 @@ void tst_QFontMetrics::metrics() fontmetrics.lineSpacing()); } } - } + } } } diff --git a/tests/auto/gui/text/qtextdocument/common.h b/tests/auto/gui/text/qtextdocument/common.h index 8fb5fe2499..184b2f7ec7 100644 --- a/tests/auto/gui/text/qtextdocument/common.h +++ b/tests/auto/gui/text/qtextdocument/common.h @@ -79,11 +79,11 @@ public: int l; void expect(int from, int oldLength, int length) { - f = from; - o = oldLength; - l = length; - error = false; - called = false; + f = from; + o = oldLength; + l = length; + error = false; + called = false; } bool error; bool called; diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index d5ddf8fbec..53aef40df0 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -187,6 +187,9 @@ private slots: void htmlExportImportBlockCount(); void QTBUG27354_spaceAndSoftSpace(); + void baseUrl_data(); + void baseUrl(); + void QTBUG28998_linkColor(); private: @@ -2947,6 +2950,53 @@ void tst_QTextDocument::QTBUG27354_spaceAndSoftSpace() } } +class BaseDocument : public QTextDocument +{ +public: + QUrl loadedResource() const { return resourceUrl; } + + QVariant loadResource(int type, const QUrl &name) + { + resourceUrl = name; + return QTextDocument::loadResource(type, name); + } + +private: + QUrl resourceUrl; +}; + +void tst_QTextDocument::baseUrl_data() +{ + QTest::addColumn<QUrl>("base"); + QTest::addColumn<QUrl>("resource"); + QTest::addColumn<QUrl>("loaded"); + + QTest::newRow("1") << QUrl() << QUrl("images/logo.png") << QUrl("images/logo.png"); + QTest::newRow("2") << QUrl("file:///path/to/content") << QUrl("images/logo.png") << QUrl("file:///path/to/images/logo.png"); + QTest::newRow("3") << QUrl("file:///path/to/content/") << QUrl("images/logo.png") << QUrl("file:///path/to/content/images/logo.png"); + QTest::newRow("4") << QUrl("file:///path/to/content/images") << QUrl("images/logo.png") << QUrl("file:///path/to/content/images/logo.png"); + QTest::newRow("5") << QUrl("file:///path/to/content/images/") << QUrl("images/logo.png") << QUrl("file:///path/to/content/images/images/logo.png"); + QTest::newRow("6") << QUrl("file:///path/to/content/images") << QUrl("../images/logo.png") << QUrl("file:///path/to/images/logo.png"); + QTest::newRow("7") << QUrl("file:///path/to/content/images/") << QUrl("../images/logo.png") << QUrl("file:///path/to/content/images/logo.png"); + QTest::newRow("8") << QUrl("file:///path/to/content/index.html") << QUrl("images/logo.png") << QUrl("file:///path/to/content/images/logo.png"); +} + +void tst_QTextDocument::baseUrl() +{ + QFETCH(QUrl, base); + QFETCH(QUrl, resource); + QFETCH(QUrl, loaded); + + BaseDocument document; + QVERIFY(!document.baseUrl().isValid()); + document.setBaseUrl(base); + QCOMPARE(document.baseUrl(), base); + + document.setHtml(QString("<img src='%1'/>").arg(resource.toString())); + document.resource(QTextDocument::ImageResource, resource); + QCOMPARE(document.loadedResource(), loaded); +} + void tst_QTextDocument::QTBUG28998_linkColor() { QPalette pal; diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index 9f9b6acb02..4274753c37 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -266,6 +266,7 @@ private slots: void html_metaInBody(); void html_importImageWithoutAspectRatio(); void html_fromFirefox(); + void html_emptyInlineInsideBlock(); private: inline void setHtml(const QString &html) @@ -360,8 +361,8 @@ void tst_QTextDocumentFragment::listCopying2() cursor.movePosition(QTextCursor::Start); int listItemCount = 0; do { - if (cursor.currentList()) - listItemCount++; + if (cursor.currentList()) + listItemCount++; } while (cursor.movePosition(QTextCursor::NextBlock)); QCOMPARE(listItemCount, 4); @@ -378,35 +379,35 @@ void tst_QTextDocumentFragment::tableCopying() // as the pasiveness of the tablemanager. QTextDocumentFragment fragment; { - QTextDocument doc; - QTextCursor cursor(&doc); + QTextDocument doc; + QTextCursor cursor(&doc); - QTextTableFormat fmt; - QTextTable *table = cursor.insertTable(2, 2, fmt); + QTextTableFormat fmt; + QTextTable *table = cursor.insertTable(2, 2, fmt); - table->cellAt(0, 0).firstCursorPosition().insertText("First Cell"); - table->cellAt(0, 1).firstCursorPosition().insertText("Second Cell"); - table->cellAt(1, 0).firstCursorPosition().insertText("Third Cell"); - table->cellAt(1, 1).firstCursorPosition().insertText("Fourth Cell"); + table->cellAt(0, 0).firstCursorPosition().insertText("First Cell"); + table->cellAt(0, 1).firstCursorPosition().insertText("Second Cell"); + table->cellAt(1, 0).firstCursorPosition().insertText("Third Cell"); + table->cellAt(1, 1).firstCursorPosition().insertText("Fourth Cell"); - fragment = QTextDocumentFragment(&doc); + fragment = QTextDocumentFragment(&doc); } { - QTextDocument doc; - QTextCursor cursor(&doc); + QTextDocument doc; + QTextCursor cursor(&doc); - cursor.insertText("FooBar"); - cursor.insertBlock(); - cursor.movePosition(QTextCursor::Left); + cursor.insertText("FooBar"); + cursor.insertBlock(); + cursor.movePosition(QTextCursor::Left); - cursor.insertFragment(fragment); - cursor.movePosition(QTextCursor::Start); - cursor.movePosition(QTextCursor::NextBlock); + cursor.insertFragment(fragment); + cursor.movePosition(QTextCursor::Start); + cursor.movePosition(QTextCursor::NextBlock); - QTextTable *table = cursor.currentTable(); - QVERIFY(table); - QCOMPARE(table->rows(), 2); - QCOMPARE(table->columns(), 2); + QTextTable *table = cursor.currentTable(); + QVERIFY(table); + QCOMPARE(table->rows(), 2); + QCOMPARE(table->columns(), 2); } } @@ -488,91 +489,91 @@ void tst_QTextDocumentFragment::tableImport() void tst_QTextDocumentFragment::tableImport2() { { - const char html[] = "" - "<table>" - "<tr><td>First Cell</td><td>Second Cell</td></tr>" - "<tr><td>Third Cell</td><td>Fourth Cell</td></tr>" - "</table>"; - - QTextDocument doc; - QTextCursor cursor(&doc); - cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(html, sizeof(html) / sizeof(html[0])))); - - cursor.movePosition(QTextCursor::Start); - cursor.movePosition(QTextCursor::NextBlock); - QTextTable *table = cursor.currentTable(); - QVERIFY(table); - QCOMPARE(table->columns(), 2); - QCOMPARE(table->rows(), 2); + const char html[] = "" + "<table>" + "<tr><td>First Cell</td><td>Second Cell</td></tr>" + "<tr><td>Third Cell</td><td>Fourth Cell</td></tr>" + "</table>"; + + QTextDocument doc; + QTextCursor cursor(&doc); + cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(html, sizeof(html) / sizeof(html[0])))); + + cursor.movePosition(QTextCursor::Start); + cursor.movePosition(QTextCursor::NextBlock); + QTextTable *table = cursor.currentTable(); + QVERIFY(table); + QCOMPARE(table->columns(), 2); + QCOMPARE(table->rows(), 2); } { - const char html[] = "" - "<table>" - "<tr><td>First Cell</td><td>Second Cell</td></tr>" - "<tr><td>Third Cell</td><td>" - " <table>" - " <tr><td>First Nested Cell</td><td>Second Nested Cell</td></tr>" - " <tr><td>Third Nested Cell</td><td>Fourth Nested Cell</td></tr>" - " <tr><td>Fifth Nested Cell</td><td>Sixth Nested Cell</td></tr>" - " </table></td></tr>" - "</table>"; - - QTextDocument doc; - QTextCursor cursor(&doc); - cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(html, sizeof(html) / sizeof(html[0])))); - - cursor.movePosition(QTextCursor::Start); - cursor.movePosition(QTextCursor::NextBlock); - QTextTable *table = cursor.currentTable(); - QVERIFY(table); - QCOMPARE(table->columns(), 2); - QCOMPARE(table->rows(), 2); + const char html[] = "" + "<table>" + "<tr><td>First Cell</td><td>Second Cell</td></tr>" + "<tr><td>Third Cell</td><td>" + " <table>" + " <tr><td>First Nested Cell</td><td>Second Nested Cell</td></tr>" + " <tr><td>Third Nested Cell</td><td>Fourth Nested Cell</td></tr>" + " <tr><td>Fifth Nested Cell</td><td>Sixth Nested Cell</td></tr>" + " </table></td></tr>" + "</table>"; + + QTextDocument doc; + QTextCursor cursor(&doc); + cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(html, sizeof(html) / sizeof(html[0])))); + + cursor.movePosition(QTextCursor::Start); + cursor.movePosition(QTextCursor::NextBlock); + QTextTable *table = cursor.currentTable(); + QVERIFY(table); + QCOMPARE(table->columns(), 2); + QCOMPARE(table->rows(), 2); /* - QTextCursor fourthCell = table->cellAt(1, 1).firstCursorPosition(); - fourthCell.movePosition(QTextCursor::NextBlock); - table = fourthCell.currentTable(); - QVERIFY(table); - QVERIFY(table != cursor.currentTable()); - QCOMPARE(table->columns(), 2); - QCOMPARE(table->rows(), 3); + QTextCursor fourthCell = table->cellAt(1, 1).firstCursorPosition(); + fourthCell.movePosition(QTextCursor::NextBlock); + table = fourthCell.currentTable(); + QVERIFY(table); + QVERIFY(table != cursor.currentTable()); + QCOMPARE(table->columns(), 2); + QCOMPARE(table->rows(), 3); */ } { - const char buggyHtml[] = "" - "<table>" - "<tr><td>First Cell<td>Second Cell" - "<tr><td>Third Cell<td>Fourth Cell" - "</table>"; - - QTextDocument doc; - QTextCursor cursor(&doc); - cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(buggyHtml, sizeof(buggyHtml) / sizeof(buggyHtml[0])))); - - cursor.movePosition(QTextCursor::Start); - cursor.movePosition(QTextCursor::NextBlock); - QTextTable *table = cursor.currentTable(); - QVERIFY(table); - QCOMPARE(table->columns(), 2); - QCOMPARE(table->rows(), 2); + const char buggyHtml[] = "" + "<table>" + "<tr><td>First Cell<td>Second Cell" + "<tr><td>Third Cell<td>Fourth Cell" + "</table>"; + + QTextDocument doc; + QTextCursor cursor(&doc); + cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(buggyHtml, sizeof(buggyHtml) / sizeof(buggyHtml[0])))); + + cursor.movePosition(QTextCursor::Start); + cursor.movePosition(QTextCursor::NextBlock); + QTextTable *table = cursor.currentTable(); + QVERIFY(table); + QCOMPARE(table->columns(), 2); + QCOMPARE(table->rows(), 2); } { - const char buggyHtml[] = "" - "<table>" - "<tr><th>First Cell<th>Second Cell" - "<tr><td>Third Cell<td>Fourth Cell" - "</table>"; - - QTextDocument doc; - QTextCursor cursor(&doc); - cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(buggyHtml, sizeof(buggyHtml) / sizeof(buggyHtml[0])))); - - cursor.movePosition(QTextCursor::Start); - cursor.movePosition(QTextCursor::NextBlock); - QTextTable *table = cursor.currentTable(); - QVERIFY(table); - QCOMPARE(table->columns(), 2); - QCOMPARE(table->rows(), 2); + const char buggyHtml[] = "" + "<table>" + "<tr><th>First Cell<th>Second Cell" + "<tr><td>Third Cell<td>Fourth Cell" + "</table>"; + + QTextDocument doc; + QTextCursor cursor(&doc); + cursor.insertFragment(QTextDocumentFragment::fromHtml(QByteArray::fromRawData(buggyHtml, sizeof(buggyHtml) / sizeof(buggyHtml[0])))); + + cursor.movePosition(QTextCursor::Start); + cursor.movePosition(QTextCursor::NextBlock); + QTextTable *table = cursor.currentTable(); + QVERIFY(table); + QCOMPARE(table->columns(), 2); + QCOMPARE(table->rows(), 2); } } @@ -4004,5 +4005,11 @@ void tst_QTextDocumentFragment::html_fromFirefox() QCOMPARE(doc->toPlainText(), QString::fromLatin1("Test Text ")); } +void tst_QTextDocumentFragment::html_emptyInlineInsideBlock() +{ + doc->setHtml(QString::fromLatin1("<!--StartFragment--><blockquote><span/>Foobar</blockquote><!--EndFragment-->")); + QVERIFY(doc->firstBlock().blockFormat().leftMargin() > 0); +} + QTEST_MAIN(tst_QTextDocumentFragment) #include "tst_qtextdocumentfragment.moc" diff --git a/tests/auto/gui/text/qtextformat/qtextformat.pro b/tests/auto/gui/text/qtextformat/qtextformat.pro index b137dac9eb..c64d266916 100644 --- a/tests/auto/gui/text/qtextformat/qtextformat.pro +++ b/tests/auto/gui/text/qtextformat/qtextformat.pro @@ -1,5 +1,5 @@ CONFIG += testcase CONFIG += parallel_test TARGET = tst_qtextformat -QT += testlib +QT += testlib core-private gui-private SOURCES += tst_qtextformat.cpp diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp index 1eb073d3b4..beb5069f06 100644 --- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp +++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp @@ -46,6 +46,7 @@ #include <qdebug.h> #include <qsettings.h> #include <qtextformat.h> +#include <private/qtextformat_p.h> #include <qtextdocument.h> #include <qtextcursor.h> #include <qtextobject.h> @@ -68,6 +69,10 @@ private slots: void getSetTabs(); void testTabsUsed(); void testFontStyleSetters(); + void setFont_data(); + void setFont(); + void setFont_collection_data(); + void setFont_collection(); }; /*! \internal @@ -410,5 +415,243 @@ void tst_QTextFormat::testFontStyleSetters() QCOMPARE(format.font().kerning(), false); } +Q_DECLARE_METATYPE(QTextCharFormat) + +void tst_QTextFormat::setFont_data() +{ + QTest::addColumn<QTextCharFormat>("format1"); + QTest::addColumn<QTextCharFormat>("format2"); + QTest::addColumn<bool>("overrideAll"); + + QTextCharFormat format1; + format1.setFontStyleHint(QFont::Serif); + format1.setFontStyleStrategy(QFont::PreferOutline); + format1.setFontCapitalization(QFont::AllUppercase); + format1.setFontKerning(true); + + { + QTest::newRow("noop|override") << format1 << format1 << true; + QTest::newRow("noop|inherit") << format1 << format1 << false; + } + + { + QTextCharFormat format2; + format2.setFontStyleHint(QFont::SansSerif); + format2.setFontStyleStrategy(QFont::PreferAntialias); + format2.setFontCapitalization(QFont::MixedCase); + format2.setFontKerning(false); + + QTest::newRow("coverage|override") << format1 << format2 << true; + QTest::newRow("coverage|inherit") << format1 << format2 << false; + } + + { + QTextCharFormat format2; + format2.setFontStyleHint(QFont::SansSerif); + format2.setFontStyleStrategy(QFont::PreferAntialias); + + QTest::newRow("partial|override") << format1 << format2 << true; + QTest::newRow("partial|inherit") << format1 << format2 << false; + } +} + +void tst_QTextFormat::setFont() +{ + QFETCH(QTextCharFormat, format1); + QFETCH(QTextCharFormat, format2); + QFETCH(bool, overrideAll); + + QTextCharFormat f; + + f.merge(format1); + QCOMPARE((int)f.fontStyleHint(), (int)format1.fontStyleHint()); + QCOMPARE((int)f.fontStyleStrategy(), (int)format1.fontStyleStrategy()); + QCOMPARE((int)f.fontCapitalization(), (int)format1.fontCapitalization()); + QCOMPARE(f.fontKerning(), format1.fontKerning()); + + QCOMPARE((int)f.font().styleHint(), (int)f.fontStyleHint()); + QCOMPARE((int)f.font().styleStrategy(), (int)f.fontStyleStrategy()); + QCOMPARE((int)f.font().capitalization(), (int)f.fontCapitalization()); + QCOMPARE(f.font().kerning(), f.fontKerning()); + + f.merge(format2); + QCOMPARE((int)f.font().styleHint(), (int)f.fontStyleHint()); + QCOMPARE((int)f.font().styleStrategy(), (int)f.fontStyleStrategy()); + QCOMPARE((int)f.font().capitalization(), (int)f.fontCapitalization()); + QCOMPARE(f.font().kerning(), f.fontKerning()); + + if (format2.hasProperty(QTextFormat::FontStyleHint)) + QCOMPARE((int)f.font().styleHint(), (int)format2.fontStyleHint()); + else + QCOMPARE((int)f.font().styleHint(), (int)format1.fontStyleHint()); + if (format2.hasProperty(QTextFormat::FontStyleStrategy)) + QCOMPARE((int)f.font().styleStrategy(), (int)format2.fontStyleStrategy()); + else + QCOMPARE((int)f.font().styleStrategy(), (int)format1.fontStyleStrategy()); + if (format2.hasProperty(QTextFormat::FontCapitalization)) + QCOMPARE((int)f.font().capitalization(), (int)format2.fontCapitalization()); + else + QCOMPARE((int)f.font().capitalization(), (int)format1.fontCapitalization()); + if (format2.hasProperty(QTextFormat::FontKerning)) + QCOMPARE(f.font().kerning(), format2.fontKerning()); + else + QCOMPARE(f.font().kerning(), format1.fontKerning()); + + + QFont font1 = format1.font(); + QFont font2 = format2.font(); + + f = QTextCharFormat(); + + { + QTextCharFormat tmp; + tmp.setFont(font1, overrideAll ? QTextCharFormat::FontPropertiesAll + : QTextCharFormat::FontPropertiesSpecifiedOnly); + f.merge(tmp); + } + QCOMPARE((int)f.fontStyleHint(), (int)format1.fontStyleHint()); + QCOMPARE((int)f.fontStyleStrategy(), (int)format1.fontStyleStrategy()); + QCOMPARE((int)f.fontCapitalization(), (int)format1.fontCapitalization()); + QCOMPARE(f.fontKerning(), format1.fontKerning()); + + QCOMPARE((int)f.font().styleHint(), (int)f.fontStyleHint()); + QCOMPARE((int)f.font().styleStrategy(), (int)f.fontStyleStrategy()); + QCOMPARE((int)f.font().capitalization(), (int)f.fontCapitalization()); + QCOMPARE(f.font().kerning(), f.fontKerning()); + + { + QTextCharFormat tmp; + tmp.setFont(font2, overrideAll ? QTextCharFormat::FontPropertiesAll + : QTextCharFormat::FontPropertiesSpecifiedOnly); + f.merge(tmp); + } + QCOMPARE((int)f.font().styleHint(), (int)f.fontStyleHint()); + QCOMPARE((int)f.font().styleStrategy(), (int)f.fontStyleStrategy()); + QCOMPARE((int)f.font().capitalization(), (int)f.fontCapitalization()); + QCOMPARE(f.font().kerning(), f.fontKerning()); + + if (overrideAll || (font2.resolve() & QFont::StyleHintResolved)) + QCOMPARE((int)f.font().styleHint(), (int)font2.styleHint()); + else + QCOMPARE((int)f.font().styleHint(), (int)font1.styleHint()); + if (overrideAll || (font2.resolve() & QFont::StyleStrategyResolved)) + QCOMPARE((int)f.font().styleStrategy(), (int)font2.styleStrategy()); + else + QCOMPARE((int)f.font().styleStrategy(), (int)font1.styleStrategy()); + if (overrideAll || (font2.resolve() & QFont::CapitalizationResolved)) + QCOMPARE((int)f.font().capitalization(), (int)font2.capitalization()); + else + QCOMPARE((int)f.font().capitalization(), (int)font1.capitalization()); + if (overrideAll || (font2.resolve() & QFont::KerningResolved)) + QCOMPARE(f.font().kerning(), font2.kerning()); + else + QCOMPARE(f.font().kerning(), font1.kerning()); +} + +void tst_QTextFormat::setFont_collection_data() +{ + setFont_data(); +} + +void tst_QTextFormat::setFont_collection() +{ + QFETCH(QTextCharFormat, format1); + QFETCH(QTextCharFormat, format2); + QFETCH(bool, overrideAll); + + QFont font1 = format1.font(); + QFont font2 = format2.font(); + + { + QTextFormatCollection collection; + collection.setDefaultFont(font1); + + int formatIndex = collection.indexForFormat(format1); + QTextCharFormat f = collection.charFormat(formatIndex); + + QCOMPARE((int)f.fontStyleHint(), (int)format1.fontStyleHint()); + QCOMPARE((int)f.fontStyleStrategy(), (int)format1.fontStyleStrategy()); + QCOMPARE((int)f.fontCapitalization(), (int)format1.fontCapitalization()); + QCOMPARE(f.fontKerning(), format1.fontKerning()); + + QCOMPARE((int)f.font().styleHint(), (int)f.fontStyleHint()); + QCOMPARE((int)f.font().styleStrategy(), (int)f.fontStyleStrategy()); + QCOMPARE((int)f.font().capitalization(), (int)f.fontCapitalization()); + QCOMPARE(f.font().kerning(), f.fontKerning()); + } + { + QTextFormatCollection collection; + collection.setDefaultFont(font1); + + int formatIndex = collection.indexForFormat(format2); + QTextCharFormat f = collection.charFormat(formatIndex); + + if (format2.hasProperty(QTextFormat::FontStyleHint)) + QCOMPARE((int)f.font().styleHint(), (int)format2.fontStyleHint()); + else + QCOMPARE((int)f.font().styleHint(), (int)format1.fontStyleHint()); + if (format2.hasProperty(QTextFormat::FontStyleStrategy)) + QCOMPARE((int)f.font().styleStrategy(), (int)format2.fontStyleStrategy()); + else + QCOMPARE((int)f.font().styleStrategy(), (int)format1.fontStyleStrategy()); + if (format2.hasProperty(QTextFormat::FontCapitalization)) + QCOMPARE((int)f.font().capitalization(), (int)format2.fontCapitalization()); + else + QCOMPARE((int)f.font().capitalization(), (int)format1.fontCapitalization()); + if (format2.hasProperty(QTextFormat::FontKerning)) + QCOMPARE(f.font().kerning(), format2.fontKerning()); + else + QCOMPARE(f.font().kerning(), format1.fontKerning()); + } + + { + QTextFormatCollection collection; + collection.setDefaultFont(font1); + + QTextCharFormat tmp; + tmp.setFont(font1, overrideAll ? QTextCharFormat::FontPropertiesAll + : QTextCharFormat::FontPropertiesSpecifiedOnly); + int formatIndex = collection.indexForFormat(tmp); + QTextCharFormat f = collection.charFormat(formatIndex); + + QCOMPARE((int)f.fontStyleHint(), (int)format1.fontStyleHint()); + QCOMPARE((int)f.fontStyleStrategy(), (int)format1.fontStyleStrategy()); + QCOMPARE((int)f.fontCapitalization(), (int)format1.fontCapitalization()); + QCOMPARE(f.fontKerning(), format1.fontKerning()); + + QCOMPARE((int)f.font().styleHint(), (int)f.fontStyleHint()); + QCOMPARE((int)f.font().styleStrategy(), (int)f.fontStyleStrategy()); + QCOMPARE((int)f.font().capitalization(), (int)f.fontCapitalization()); + QCOMPARE(f.font().kerning(), f.fontKerning()); + } + { + QTextFormatCollection collection; + collection.setDefaultFont(font1); + + QTextCharFormat tmp; + tmp.setFont(font2, overrideAll ? QTextCharFormat::FontPropertiesAll + : QTextCharFormat::FontPropertiesSpecifiedOnly); + int formatIndex = collection.indexForFormat(tmp); + QTextCharFormat f = collection.charFormat(formatIndex); + + if (overrideAll || (font2.resolve() & QFont::StyleHintResolved)) + QCOMPARE((int)f.font().styleHint(), (int)font2.styleHint()); + else + QCOMPARE((int)f.font().styleHint(), (int)font1.styleHint()); + if (overrideAll || (font2.resolve() & QFont::StyleStrategyResolved)) + QCOMPARE((int)f.font().styleStrategy(), (int)font2.styleStrategy()); + else + QCOMPARE((int)f.font().styleStrategy(), (int)font1.styleStrategy()); + if (overrideAll || (font2.resolve() & QFont::CapitalizationResolved)) + QCOMPARE((int)f.font().capitalization(), (int)font2.capitalization()); + else + QCOMPARE((int)f.font().capitalization(), (int)font1.capitalization()); + if (overrideAll || (font2.resolve() & QFont::KerningResolved)) + QCOMPARE(f.font().kerning(), font2.kerning()); + else + QCOMPARE(f.font().kerning(), font1.kerning()); + } +} + QTEST_MAIN(tst_QTextFormat) #include "tst_qtextformat.moc" diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 90137079f3..56d6711dc6 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -212,63 +212,63 @@ void tst_QTextLayout::lineBreaking() { #if 0 struct Breaks { - const char *utf8; - uchar breaks[32]; + const char *utf8; + uchar breaks[32]; }; Breaks brks[] = { - { "11", { false, 0xff } }, - { "aa", { false, 0xff } }, - { "++", { false, 0xff } }, - { "--", { false, 0xff } }, - { "((", { false, 0xff } }, - { "))", { false, 0xff } }, - { "..", { false, 0xff } }, - { "\"\"", { false, 0xff } }, - { "$$", { false, 0xff } }, - { "!!", { false, 0xff } }, - { "??", { false, 0xff } }, - { ",,", { false, 0xff } }, - - { ")()", { true, false, 0xff } }, - { "?!?", { false, false, 0xff } }, - { ".,.", { false, false, 0xff } }, - { "+-+", { false, false, 0xff } }, - { "+=+", { false, false, 0xff } }, - { "+(+", { false, false, 0xff } }, - { "+)+", { false, false, 0xff } }, - - { "a b", { false, true, 0xff } }, - { "a(b", { false, false, 0xff } }, - { "a)b", { false, false, 0xff } }, - { "a-b", { false, true, 0xff } }, - { "a.b", { false, false, 0xff } }, - { "a+b", { false, false, 0xff } }, - { "a?b", { false, false, 0xff } }, - { "a!b", { false, false, 0xff } }, - { "a$b", { false, false, 0xff } }, - { "a,b", { false, false, 0xff } }, - { "a/b", { false, false, 0xff } }, - { "1/2", { false, false, 0xff } }, - { "./.", { false, false, 0xff } }, - { ",/,", { false, false, 0xff } }, - { "!/!", { false, false, 0xff } }, - { "\\/\\", { false, false, 0xff } }, - { "1 2", { false, true, 0xff } }, - { "1(2", { false, false, 0xff } }, - { "1)2", { false, false, 0xff } }, - { "1-2", { false, false, 0xff } }, - { "1.2", { false, false, 0xff } }, - { "1+2", { false, false, 0xff } }, - { "1?2", { false, true, 0xff } }, - { "1!2", { false, true, 0xff } }, - { "1$2", { false, false, 0xff } }, - { "1,2", { false, false, 0xff } }, - { "1/2", { false, false, 0xff } }, - { "\330\260\331\216\331\204\331\220\331\203\331\216", { false, false, false, false, false, 0xff } }, - { "\330\247\331\204\331\205 \330\247\331\204\331\205", { false, false, false, true, false, false, 0xff } }, - { "1#2", { false, false, 0xff } }, - { "!#!", { false, false, 0xff } }, - { 0, {} } + { "11", { false, 0xff } }, + { "aa", { false, 0xff } }, + { "++", { false, 0xff } }, + { "--", { false, 0xff } }, + { "((", { false, 0xff } }, + { "))", { false, 0xff } }, + { "..", { false, 0xff } }, + { "\"\"", { false, 0xff } }, + { "$$", { false, 0xff } }, + { "!!", { false, 0xff } }, + { "??", { false, 0xff } }, + { ",,", { false, 0xff } }, + + { ")()", { true, false, 0xff } }, + { "?!?", { false, false, 0xff } }, + { ".,.", { false, false, 0xff } }, + { "+-+", { false, false, 0xff } }, + { "+=+", { false, false, 0xff } }, + { "+(+", { false, false, 0xff } }, + { "+)+", { false, false, 0xff } }, + + { "a b", { false, true, 0xff } }, + { "a(b", { false, false, 0xff } }, + { "a)b", { false, false, 0xff } }, + { "a-b", { false, true, 0xff } }, + { "a.b", { false, false, 0xff } }, + { "a+b", { false, false, 0xff } }, + { "a?b", { false, false, 0xff } }, + { "a!b", { false, false, 0xff } }, + { "a$b", { false, false, 0xff } }, + { "a,b", { false, false, 0xff } }, + { "a/b", { false, false, 0xff } }, + { "1/2", { false, false, 0xff } }, + { "./.", { false, false, 0xff } }, + { ",/,", { false, false, 0xff } }, + { "!/!", { false, false, 0xff } }, + { "\\/\\", { false, false, 0xff } }, + { "1 2", { false, true, 0xff } }, + { "1(2", { false, false, 0xff } }, + { "1)2", { false, false, 0xff } }, + { "1-2", { false, false, 0xff } }, + { "1.2", { false, false, 0xff } }, + { "1+2", { false, false, 0xff } }, + { "1?2", { false, true, 0xff } }, + { "1!2", { false, true, 0xff } }, + { "1$2", { false, false, 0xff } }, + { "1,2", { false, false, 0xff } }, + { "1/2", { false, false, 0xff } }, + { "\330\260\331\216\331\204\331\220\331\203\331\216", { false, false, false, false, false, 0xff } }, + { "\330\247\331\204\331\205 \330\247\331\204\331\205", { false, false, false, true, false, false, 0xff } }, + { "1#2", { false, false, 0xff } }, + { "!#!", { false, false, 0xff } }, + { 0, {} } }; Breaks *b = brks; while (b->utf8) { diff --git a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp index 10a25ba437..0628cc66d1 100644 --- a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp +++ b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp @@ -119,7 +119,7 @@ void tst_QTextList::autoNumbering() QVERIFY(list); for (int i = 0; i < 27; ++i) - cursor.insertBlock(); + cursor.insertBlock(); QVERIFY(list->count() == 28); diff --git a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp index 3359cc8d32..5efb532233 100644 --- a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp +++ b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp @@ -158,12 +158,12 @@ void tst_QTextPieceTable::insertion3() { QString compare; for (int i = 0; i < 20000; ++i) { - int pos = rand() % (i+1); - QChar c((unsigned short)(i & 0xff) + 1); - QString str; - str += c; - table->insert(pos, str, charFormatIndex); - compare.insert(pos, str); + int pos = rand() % (i+1); + QChar c((unsigned short)(i & 0xff) + 1); + QString str; + str += c; + table->insert(pos, str, charFormatIndex); + compare.insert(pos, str); } QVERIFY(table->plainText() == compare); } @@ -172,17 +172,17 @@ void tst_QTextPieceTable::insertion4() { QString compare; for (int i = 0; i < 20000; ++i) { - int pos = rand() % (i+1); - QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); - QString str; - str += c; - str += c; - table->insert(pos, str, charFormatIndex); - compare.insert(pos, str); - // if (table->text() != compare) { - // qDebug("compare failed: i=%d (current char=%c) insert at %d\nexpected '%s'\ngot '%s'", i, (i % 26) + (i>25?'A':'a'), pos, compare.latin1(), table->text().latin1()); - // exit(12); - // } + int pos = rand() % (i+1); + QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); + QString str; + str += c; + str += c; + table->insert(pos, str, charFormatIndex); + compare.insert(pos, str); +// if (table->text() != compare) { +// qDebug("compare failed: i=%d (current char=%c) insert at %d\nexpected '%s'\ngot '%s'", i, (i % 26) + (i>25?'A':'a'), pos, compare.latin1(), table->text().latin1()); +// exit(12); +// } } QVERIFY(table->plainText() == compare); } @@ -191,23 +191,23 @@ void tst_QTextPieceTable::insertion5() { QString compare; for (int i = 0; i < 20000; ++i) { - int pos = rand() % (i+1); - QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); - QString str; - str += c; - str += c; - if (c == 'a') { - table->insertBlock(pos, blockFormatIndex, charFormatIndex); - str = QChar(QChar::ParagraphSeparator); - } else { - table->insert(pos, str, charFormatIndex); - } - compare.insert(pos, str); + int pos = rand() % (i+1); + QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); + QString str; + str += c; + str += c; + if (c == 'a') { + table->insertBlock(pos, blockFormatIndex, charFormatIndex); + str = QChar(QChar::ParagraphSeparator); + } else { + table->insert(pos, str, charFormatIndex); + } + compare.insert(pos, str); } QVERIFY(table->plainText() == compare); for (QTextBlock it = table->blocksBegin(); it != table->blocksEnd(); it = it.next()) { - QTextDocumentPrivate::FragmentIterator fit = table->find(it.position()); - QVERIFY(fit.position() == it.position()); + QTextDocumentPrivate::FragmentIterator fit = table->find(it.position()); + QVERIFY(fit.position() == it.position()); } } @@ -249,24 +249,24 @@ void tst_QTextPieceTable::removal3() QString compare; int l = 0; for (int i = 0; i < 20000; ++i) { - bool remove = l && (rand() % 2); - int pos = rand() % (remove ? l : (l+1)); - QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); - QString str; - str += c; - str += c; - if (remove && pos < table->length()) { - compare.remove(pos, 1); - table->remove(pos, 1); - } else { - compare.insert(pos, str); - table->insert(pos, str, charFormatIndex); - } - l += remove ? -1 : 2; - // if (table->text() != compare) { - // qDebug("compare failed: i=%d (current char=%c) insert at %d\nexpected '%s'\ngot '%s'", i, (i % 26) + (i>25?'A':'a'), pos, compare.latin1(), table->text().latin1()); - // exit(12); - // } + bool remove = l && (rand() % 2); + int pos = rand() % (remove ? l : (l+1)); + QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); + QString str; + str += c; + str += c; + if (remove && pos < table->length()) { + compare.remove(pos, 1); + table->remove(pos, 1); + } else { + compare.insert(pos, str); + table->insert(pos, str, charFormatIndex); + } + l += remove ? -1 : 2; +// if (table->text() != compare) { +// qDebug("compare failed: i=%d (current char=%c) insert at %d\nexpected '%s'\ngot '%s'", i, (i % 26) + (i>25?'A':'a'), pos, compare.latin1(), table->text().latin1()); +// exit(12); +// } } QVERIFY(table->plainText() == compare); } @@ -276,31 +276,31 @@ void tst_QTextPieceTable::removal4() QString compare; int l = 0; for (int i = 0; i < 20000; ++i) { - bool remove = l && (rand() % 2); - int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0; - QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); - QString str; - if (c != 'a') { - str += c; - str += c; - } else { - str = QChar(QChar::ParagraphSeparator); - } - if (remove && pos < table->length() - 1) { - compare.remove(pos, 1); - table->remove(pos, 1); - } else { - if (str[0] == QChar(QChar::ParagraphSeparator)) - table->insertBlock(pos, blockFormatIndex, charFormatIndex); - else - table->insert(pos, str, charFormatIndex); - compare.insert(pos, str); - } - l += remove ? -1 : 2; -// if (table->plainText() != compare) { -// qDebug("compare failed: i=%d (current char=%c) insert at %d\nexpected '%s'\ngot '%s'", i, (i % 26) + (i>25?'A':'a'), pos, compare.latin1(), table->plainText().latin1()); -// exit(12); -// } + bool remove = l && (rand() % 2); + int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0; + QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); + QString str; + if (c != 'a') { + str += c; + str += c; + } else { + str = QChar(QChar::ParagraphSeparator); + } + if (remove && pos < table->length() - 1) { + compare.remove(pos, 1); + table->remove(pos, 1); + } else { + if (str[0] == QChar(QChar::ParagraphSeparator)) + table->insertBlock(pos, blockFormatIndex, charFormatIndex); + else + table->insert(pos, str, charFormatIndex); + compare.insert(pos, str); + } + l += remove ? -1 : 2; +// if (table->plainText() != compare) { +// qDebug("compare failed: i=%d (current char=%c) insert at %d\nexpected '%s'\ngot '%s'", i, (i % 26) + (i>25?'A':'a'), pos, compare.latin1(), table->plainText().latin1()); +// exit(12); +// } } QVERIFY(table->plainText() == compare); } @@ -490,27 +490,27 @@ void tst_QTextPieceTable::undoRedo11() QString compare; int l = 0; for (int i = 0; i < loops; ++i) { - bool remove = l && (rand() % 2); - int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0; - QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); - QString str; - str += c; - str += c; - if (remove) { - compare.remove(pos, 1); - table->remove(pos, 1); - } else { - compare.insert(pos, str); - table->insert(pos, str, charFormatIndex); - } - l += remove ? -1 : 2; + bool remove = l && (rand() % 2); + int pos = (l > 1) ? rand() % (remove ? l-1 : l) : 0; + QChar c((unsigned short)((i % 26) + (i>25?'A':'a'))); + QString str; + str += c; + str += c; + if (remove) { + compare.remove(pos, 1); + table->remove(pos, 1); + } else { + compare.insert(pos, str); + table->insert(pos, str, charFormatIndex); + } + l += remove ? -1 : 2; } QVERIFY(table->plainText() == compare); for (int i = 0; i < loops; ++i) - table->undo(); + table->undo(); QVERIFY(table->plainText() == QString("")); for (int i = 0; i < loops; ++i) - table->redo(); + table->redo(); QVERIFY(table->plainText() == compare); } diff --git a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp index eebac28323..74802c3217 100644 --- a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp +++ b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp @@ -1067,7 +1067,7 @@ void tst_QTextScriptEngine::controlInSyllable_qtbug14204() e->shape(0); QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(2)); - QVERIFY(e->layoutData->glyphLayout.advances_x[1] != 0); + QVERIFY(e->layoutData->glyphLayout.advances[1].toInt() != 0); #endif } @@ -1087,8 +1087,7 @@ void tst_QTextScriptEngine::combiningMarks_qtbug15675() e->shape(0); QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(4)); - QEXPECT_FAIL("", "QTBUG-23064", Abort); - QVERIFY(e->layoutData->glyphLayout.advances_y[2] > 0); + QCOMPARE(e->layoutData->glyphLayout.advances[2].toInt(), 0); #else QFontDatabase db; @@ -1106,7 +1105,7 @@ void tst_QTextScriptEngine::combiningMarks_qtbug15675() e->shape(0); QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(3)); - QVERIFY(e->layoutData->glyphLayout.advances_x[1] == 0); + QCOMPARE(e->layoutData->glyphLayout.advances[1].toInt(), 0); #endif } |