diff options
Diffstat (limited to 'tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp')
-rw-r--r-- | tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp | 269 |
1 files changed, 135 insertions, 134 deletions
diff --git a/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp index b48b751ea0..560b4a47dd 100644 --- a/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp +++ b/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QScopedValueRollback> @@ -33,9 +8,12 @@ #include <qfile.h> #include <qdebug.h> #include <qlist.h> +#include <qset.h> #include <algorithm> +using namespace Qt::Literals::StringLiterals; + class tst_QTextBoundaryFinder : public QObject { Q_OBJECT @@ -51,6 +29,9 @@ private slots: void lineBoundariesDefault(); #endif + void graphemeBoundaries_manual_data(); + void graphemeBoundaries_manual(); + void wordBoundaries_manual_data(); void wordBoundaries_manual(); void sentenceBoundaries_manual_data(); @@ -64,7 +45,6 @@ private slots: void assignmentOperator(); void isAtSoftHyphen_data(); void isAtSoftHyphen(); - void thaiLineBreak(); }; @@ -94,7 +74,7 @@ inline char *toString(const QList<int> &list) QT_END_NAMESPACE #ifdef QT_BUILD_INTERNAL -static void generateDataFromFile(const QString &fname) +static void generateDataFromFile(const QString &fname, const QSet<QString> &skipSet = {}) { QTest::addColumn<QString>("testString"); QTest::addColumn<QList<int> >("expectedBreakPositions"); @@ -102,9 +82,7 @@ static void generateDataFromFile(const QString &fname) QString testFile = QFINDTESTDATA(fname); QVERIFY2(!testFile.isEmpty(), (fname.toLatin1() + QByteArray(" not found!"))); QFile f(testFile); - QVERIFY(f.exists()); - - f.open(QIODevice::ReadOnly); + QVERIFY(f.open(QIODevice::ReadOnly)); int linenum = 0; while (!f.atEnd()) { @@ -124,7 +102,8 @@ static void generateDataFromFile(const QString &fname) QString testString; QList<int> expectedBreakPositions; - foreach (const QString &part, test.simplified().split(QLatin1Char(' '), Qt::SkipEmptyParts)) { + const QStringList parts = test.simplified().split(QLatin1Char(' '), Qt::SkipEmptyParts); + for (const QString &part : parts) { if (part.size() == 1) { if (part.at(0).unicode() == 0xf7) expectedBreakPositions.append(testString.size()); @@ -145,10 +124,12 @@ static void generateDataFromFile(const QString &fname) QVERIFY(!testString.isEmpty()); QVERIFY(!expectedBreakPositions.isEmpty()); + bool skip = false; + if (!comments.isEmpty()) { const QStringList lst = comments.simplified().split(QLatin1Char(' '), Qt::SkipEmptyParts); comments.clear(); - foreach (const QString &part, lst) { + for (const QString &part : lst) { if (part.size() == 1) { if (part.at(0).unicode() == 0xf7) comments += QLatin1Char('+'); @@ -156,13 +137,19 @@ static void generateDataFromFile(const QString &fname) comments += QLatin1Char('x'); continue; } - if (part.startsWith(QLatin1Char('(')) && part.endsWith(QLatin1Char(')'))) + if (part.startsWith(QLatin1Char('(')) && part.endsWith(QLatin1Char(')'))) { + skip |= skipSet.contains(part.sliced(1, part.length() - 2)); comments += part; + } } } const QByteArray nm = "line #" + QByteArray::number(linenum) + ": " + comments.toLatin1(); - QTest::newRow(nm.constData()) << testString << expectedBreakPositions; + + if (skip) + qDebug() << "Skipping" << nm; + else + QTest::newRow(nm.constData()) << testString << expectedBreakPositions; } } #endif @@ -208,7 +195,7 @@ static void doTestData(const QString &testString, const QList<int> &expectedBrea QVERIFY(boundaryFinder.boundaryReasons() == QTextBoundaryFinder::NotAtBoundary); // test boundaryReasons() - for (int i = 0; i <= testString.length(); ++i) { + for (int i = 0; i <= testString.size(); ++i) { boundaryFinder.setPosition(i); QCOMPARE(!!(boundaryFinder.boundaryReasons() & reasons), expectedBreakPositions.contains(i)); } @@ -222,7 +209,10 @@ QT_END_NAMESPACE void tst_QTextBoundaryFinder::graphemeBoundariesDefault_data() { - generateDataFromFile("data/GraphemeBreakTest.txt"); + + // QTBUG-121907: We are not using Unicode grapheme segmentation for Indic scripts. + QSet<QString> skipSet = {u"ConjunctLinkingScripts_LinkingConsonant"_s}; + generateDataFromFile("data/GraphemeBreakTest.txt", skipSet); } void tst_QTextBoundaryFinder::graphemeBoundariesDefault() @@ -270,7 +260,10 @@ void tst_QTextBoundaryFinder::sentenceBoundariesDefault() void tst_QTextBoundaryFinder::lineBoundariesDefault_data() { - generateDataFromFile("data/LineBreakTest.txt"); + // QTBUG-121907: Indic line breaking is not supported + QSet<QString> skipSet = {u"AK"_s, u"AP"_s, u"AS"_s, u"VI"_s, u"VF"_s}; + + generateDataFromFile("data/LineBreakTest.txt", skipSet); } void tst_QTextBoundaryFinder::lineBoundariesDefault() @@ -286,6 +279,104 @@ void tst_QTextBoundaryFinder::lineBoundariesDefault() } #endif // QT_BUILD_INTERNAL +void tst_QTextBoundaryFinder::graphemeBoundaries_manual_data() +{ + QTest::addColumn<QString>("testString"); + QTest::addColumn<QList<int>>("expectedBreakPositions"); + + { + // QTBUG-94951 + QChar s[] = { QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0xD83D), QChar(0xDCF2), // U+1F4F2 MOBILE PHONE WITH RIGHTWARDS ARROW AT LEFT + QChar(0xD83D), QChar(0xDCE9), // U+1F4E9 ENVELOPE WITH DOWNWARDS ARROW ABOVE + }; + QString testString(s, sizeof(s)/sizeof(s[0])); + + QList<int> expectedBreakPositions{0, 2, 4, 6}; + QTest::newRow("+EXTPICxEXT+EXTPIC+EXTPIC+") << testString << expectedBreakPositions; + } + + { + QChar s[] = { QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + }; + QString testString(s, sizeof(s)/sizeof(s[0])); + + QList<int> expectedBreakPositions{0, 2, 4}; + QTest::newRow("+EXTPICxEXT+EXTPICxEXT+") << testString << expectedBreakPositions; + } + + { + QChar s[] = { QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + }; + QString testString(s, sizeof(s)/sizeof(s[0])); + + QList<int> expectedBreakPositions{0, 4, 7}; + QTest::newRow("+EXTPICxEXTxEXTxEXT+EXTPICxEXTxEXT+") << testString << expectedBreakPositions; + } + + { + QChar s[] = { QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0x200D), // U+200D ZERO WIDTH JOINER + QChar(0xD83D), QChar(0xDCF2), // U+1F4F2 MOBILE PHONE WITH RIGHTWARDS ARROW AT LEFT + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + }; + QString testString(s, sizeof(s)/sizeof(s[0])); + + QList<int> expectedBreakPositions{0, 7}; + QTest::newRow("+EXTPICxEXTxEXTxZWJxEXTPICxEXTxEXT+") << testString << expectedBreakPositions; + } + + { + QChar s[] = { QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0x200D), // U+200D ZERO WIDTH JOINER + QChar(0x0041), // U+0041 LATIN CAPITAL LETTER A + QChar(0xD83D), QChar(0xDCF2), // U+1F4F2 MOBILE PHONE WITH RIGHTWARDS ARROW AT LEFT + }; + QString testString(s, sizeof(s)/sizeof(s[0])); + + QList<int> expectedBreakPositions{0, 4, 5, 7}; + QTest::newRow("+EXTPICxEXTxEXTxZWJ+Any+EXTPIC+") << testString << expectedBreakPositions; + } + + { + QChar s[] = { QChar(0x2764), // U+2764 HEAVY BLACK HEART + QChar(0xFE0F), // U+FE0F VARIATION SELECTOR-16 + QChar(0xD83C), QChar(0xDDEA), // U+1F1EA REGIONAL INDICATOR SYMBOL LETTER E + QChar(0xD83C), QChar(0xDDFA), // U+1F1FA REGIONAL INDICATOR SYMBOL LETTER U + QChar(0xD83C), QChar(0xDDEA), // U+1F1EA REGIONAL INDICATOR SYMBOL LETTER E + QChar(0xD83C), QChar(0xDDFA), // U+1F1FA REGIONAL INDICATOR SYMBOL LETTER U + QChar(0xD83C), QChar(0xDDEA), // U+1F1EA REGIONAL INDICATOR SYMBOL LETTER E + QChar(0x0041), // U+0041 LATIN CAPITAL LETTER A + }; + QString testString(s, sizeof(s)/sizeof(s[0])); + + QList<int> expectedBreakPositions{0, 2, 6, 10, 12, 13}; + QTest::newRow("+EXTPICxEXT+RIxRI+RIxRI+RI+ANY+") << testString << expectedBreakPositions; + } +} + +void tst_QTextBoundaryFinder::graphemeBoundaries_manual() +{ + QFETCH(QString, testString); + QFETCH(QList<int>, expectedBreakPositions); + + doTestData(testString, expectedBreakPositions, QTextBoundaryFinder::Grapheme); +} + void tst_QTextBoundaryFinder::wordBoundaries_manual_data() { QTest::addColumn<QString>("testString"); @@ -344,9 +435,9 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() { QString testString(QString::fromUtf8("This is a sample buffer.Please test me . He's don't Le'Clerk.")); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; - expectedBreakPositions << 0 << 4 << 5 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 20 << 21 << 27 - << 28 << 34 << 35 << 39 << 40 << 42 << 43 << 44 << 45 << 46 << 47 << 48 - << 49 << 53 << 54 << 59 << 60 << 68 << 69; + expectedBreakPositions << 0 << 4 << 5 << 7 << 12 << 13 << 14 << 20 << 21 << 27 << 28 << 34 + << 35 << 39 << 40 << 42 << 43 << 44 << 49 << 53 << 54 << 59 << 60 + << 68 << 69; expectedStartPositions << 0 << 5 << 12 << 14 << 21 << 28 << 35 << 40 << 49 << 54 << 60; expectedEndPositions << 4 << 7 << 13 << 20 << 27 << 34 << 39 << 42 << 53 << 59 << 68; @@ -692,7 +783,7 @@ void tst_QTextBoundaryFinder::emptyText() void tst_QTextBoundaryFinder::fastConstructor() { QString text("Hello World"); - QTextBoundaryFinder finder(QTextBoundaryFinder::Word, text.constData(), text.length(), /*buffer*/0, /*buffer size*/0); + QTextBoundaryFinder finder(QTextBoundaryFinder::Word, text.constData(), text.size(), /*buffer*/0, /*buffer size*/0); QCOMPARE(finder.position(), 0); QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::StartOfItem); @@ -706,7 +797,7 @@ void tst_QTextBoundaryFinder::fastConstructor() QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::StartOfItem); finder.toNextBoundary(); - QCOMPARE(finder.position(), text.length()); + QCOMPARE(finder.position(), text.size()); QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::EndOfItem); finder.toNextBoundary(); @@ -766,95 +857,5 @@ void tst_QTextBoundaryFinder::isAtSoftHyphen() doTestData(testString, expectedSoftHyphenPositions, QTextBoundaryFinder::Line, QTextBoundaryFinder::SoftHyphen); } -#if QT_CONFIG(library) -#include <qlibrary.h> -#endif - -#define LIBTHAI_MAJOR 0 -typedef int (*th_brk_def) (const unsigned char*, int*, size_t); -static th_brk_def th_brk = 0; - -static bool init_libthai() -{ -#if QT_CONFIG(library) - static bool triedResolve = false; - if (!triedResolve) { - th_brk = (th_brk_def) QLibrary::resolve("thai", (int)LIBTHAI_MAJOR, "th_brk"); - triedResolve = true; - } -#endif - return th_brk != 0; -} - -void tst_QTextBoundaryFinder::thaiLineBreak() -{ - if (!init_libthai()) - QSKIP("This test requires libThai-0.1.1x to be installed."); -#if 0 - QString text = QString::fromUtf8("สวัสดีครับ นี่เป็นการงทดสอบตัวเอ"); - - QTextBoundaryFinder finder(QTextBoundaryFinder::Line, text); - finder.setPosition(0); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(1); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(2); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(3); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(4); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(5); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(6); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(7); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(8); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(9); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(10); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(11); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(12); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(13); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(14); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(15); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(16); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(17); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(18); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(19); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(20); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(21); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(22); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(23); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(24); - QVERIFY(!finder.isAtBoundary()); - finder.setPosition(25); - QVERIFY(finder.isAtBoundary()); - finder.setPosition(26); - QVERIFY(finder.isAtBoundary()); - for (int i = 27; i < 32; ++i) { - finder.setPosition(i); - QVERIFY(!finder.isAtBoundary()); - } -#endif -} - - QTEST_MAIN(tst_QTextBoundaryFinder) #include "tst_qtextboundaryfinder.moc" |