diff options
Diffstat (limited to 'tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp')
-rw-r--r-- | tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp | 334 |
1 files changed, 173 insertions, 161 deletions
diff --git a/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp index 9c212a6a0b..560b4a47dd 100644 --- a/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp +++ b/tests/auto/corelib/text/qtextboundaryfinder/tst_qtextboundaryfinder.cpp @@ -1,40 +1,19 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QScopedValueRollback> #include <qtextboundaryfinder.h> #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 @@ -50,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(); @@ -63,7 +45,6 @@ private slots: void assignmentOperator(); void isAtSoftHyphen_data(); void isAtSoftHyphen(); - void thaiLineBreak(); }; @@ -93,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"); @@ -101,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()) { @@ -123,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()); @@ -144,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('+'); @@ -155,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 @@ -207,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)); } @@ -221,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() @@ -269,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() @@ -285,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"); @@ -293,7 +385,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() QTest::addColumn<QList<int> >("expectedEndPositions"); { - QChar s[] = { 0x000D, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 2 << 3; @@ -302,7 +394,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x000D, 0x0308, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x0308), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 2 << 3 << 4; @@ -343,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; @@ -366,7 +458,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() // Sample Strings from WordBreakTest.html { - QChar s[] = { 0x0063, 0x0061, 0x006E, 0x0027, 0x0074 }; + QChar s[] = { QChar(0x0063), QChar(0x0061), QChar(0x006E), QChar(0x0027), QChar(0x0074) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 5; @@ -377,7 +469,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0063, 0x0061, 0x006E, 0x2019, 0x0074 }; + QChar s[] = { QChar(0x0063), QChar(0x0061), QChar(0x006E), QChar(0x2019), QChar(0x0074) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 5; @@ -388,7 +480,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0061, 0x0062, 0x00AD, 0x0062, 0x0061 }; + QChar s[] = { QChar(0x0061), QChar(0x0062), QChar(0x00AD), QChar(0x0062), QChar(0x0061) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 5; @@ -399,8 +491,10 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0061, 0x0024, 0x002D, 0x0033, 0x0034, 0x002C, 0x0035, 0x0036, - 0x0037, 0x002E, 0x0031, 0x0034, 0x0025, 0x0062 }; + QChar s[] = { QChar(0x0061), QChar(0x0024), QChar(0x002D), QChar(0x0033), + QChar(0x0034), QChar(0x002C), QChar(0x0035), QChar(0x0036), + QChar(0x0037), QChar(0x002E), QChar(0x0031), QChar(0x0034), + QChar(0x0025), QChar(0x0062) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 2 << 3 << 12 << 13 << 14; @@ -411,7 +505,7 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x0033, 0x0061 }; + QChar s[] = { QChar(0x0033), QChar(0x0061) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 2; @@ -422,8 +516,9 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0063, 0x2060, 0x0061, 0x2060, 0x006E, 0x2060, 0x0027, - 0x2060, 0x0074, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0063), QChar(0x2060), QChar(0x0061), + QChar(0x2060), QChar(0x006E), QChar(0x2060), QChar(0x0027), + QChar(0x2060), QChar(0x0074), QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 12; @@ -434,8 +529,9 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0063, 0x2060, 0x0061, 0x2060, 0x006E, 0x2060, 0x2019, - 0x2060, 0x0074, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0063), QChar(0x2060), QChar(0x0061), + QChar(0x2060), QChar(0x006E), QChar(0x2060), QChar(0x2019), + QChar(0x2060), QChar(0x0074), QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 12; @@ -446,8 +542,9 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0061, 0x2060, 0x0062, 0x2060, 0x00AD, 0x2060, 0x0062, - 0x2060, 0x0061, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0061), QChar(0x2060), QChar(0x0062), + QChar(0x2060), QChar(0x00AD), QChar(0x2060), QChar(0x0062), + QChar(0x2060), QChar(0x0061), QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 12; @@ -458,10 +555,14 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0061, 0x2060, 0x0024, 0x2060, 0x002D, 0x2060, 0x0033, - 0x2060, 0x0034, 0x2060, 0x002C, 0x2060, 0x0035, 0x2060, 0x0036, - 0x2060, 0x0037, 0x2060, 0x002E, 0x2060, 0x0031, 0x2060, 0x0034, - 0x2060, 0x0025, 0x2060, 0x0062, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0061), QChar(0x2060), QChar(0x0024), + QChar(0x2060), QChar(0x002D), QChar(0x2060), QChar(0x0033), + QChar(0x2060), QChar(0x0034), QChar(0x2060), QChar(0x002C), + QChar(0x2060), QChar(0x0035), QChar(0x2060), QChar(0x0036), + QChar(0x2060), QChar(0x0037), QChar(0x2060), QChar(0x002E), + QChar(0x2060), QChar(0x0031), QChar(0x2060), QChar(0x0034), + QChar(0x2060), QChar(0x0025), QChar(0x2060), QChar(0x0062), + QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 3 << 5 << 7 << 25 << 27 << 30; @@ -472,7 +573,8 @@ void tst_QTextBoundaryFinder::wordBoundaries_manual_data() << expectedStartPositions << expectedEndPositions; } { - QChar s[] = { 0x2060, 0x0033, 0x2060, 0x0061, 0x2060, 0x2060 }; + QChar s[] = { QChar(0x2060), QChar(0x0033), QChar(0x2060), QChar(0x0061), + QChar(0x2060), QChar(0x2060) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedStartPositions, expectedEndPositions; expectedBreakPositions << 0 << 1 << 6; @@ -502,7 +604,7 @@ void tst_QTextBoundaryFinder::sentenceBoundaries_manual_data() QTest::addColumn<QList<int> >("expectedBreakPositions"); { - QChar s[] = { 0x000D, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions; expectedBreakPositions << 0 << 2 << 3; @@ -510,7 +612,7 @@ void tst_QTextBoundaryFinder::sentenceBoundaries_manual_data() QTest::newRow("+CRxLF+LF+") << testString << expectedBreakPositions; } { - QChar s[] = { 0x000D, 0x0308, 0x000A, 0x000A }; + QChar s[] = { QChar(0x000D), QChar(0x0308), QChar(0x000A), QChar(0x000A) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions; expectedBreakPositions << 0 << 1 << 3 << 4; @@ -587,7 +689,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() } { - QChar s[] = { 0x000D, 0x0308, 0x000A, 0x000A, 0x0020 }; + QChar s[] = { QChar(0x000D), QChar(0x0308), QChar(0x000A), QChar(0x000A), QChar(0x0020) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 1 << 3 << 4 << 5; @@ -597,7 +699,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() << expectedMandatoryBreakPositions; } { - QChar s[] = { 0x000A, 0x2E80, 0x0308, 0x0023, 0x0023 }; + QChar s[] = { QChar(0x000A), QChar(0x2E80), QChar(0x0308), QChar(0x0023), QChar(0x0023) }; QString testString(s, sizeof(s)/sizeof(QChar)); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 1 << 3 << 5; @@ -607,7 +709,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() << expectedMandatoryBreakPositions; } { - QChar s[] = { 0x000A, 0x0308, 0x0023, 0x0023 }; + QChar s[] = { QChar(0x000A), QChar(0x0308), QChar(0x0023), QChar(0x0023) }; QString testString(s, sizeof(s)/sizeof(QChar)); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 1 << 4; @@ -618,7 +720,7 @@ void tst_QTextBoundaryFinder::lineBoundaries_manual_data() } { - QChar s[] = { 0x0061, 0x00AD, 0x0062, 0x0009, 0x0063, 0x0064 }; + QChar s[] = { QChar(0x0061), QChar(0x00AD), QChar(0x0062), QChar(0x0009), QChar(0x0063), QChar(0x0064) }; QString testString(s, sizeof(s)/sizeof(s[0])); QList<int> expectedBreakPositions, expectedMandatoryBreakPositions; expectedBreakPositions << 0 << 2 << 4 << 6; @@ -681,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); @@ -695,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(); @@ -755,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" |