add tests and benchmarks for QString::toLower()/toUpper()/toCaseFolded()
Merge-request: 70 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com> Change-Id: I3929d4d8963c3cef6d2c6420d8ad1f7a45f7e042 Reviewed-by: Olivier Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
1ddecb0aa2
commit
ebe43992f9
@ -121,8 +121,9 @@ private slots:
|
|||||||
void simplified_data();
|
void simplified_data();
|
||||||
void simplified();
|
void simplified();
|
||||||
void trimmed();
|
void trimmed();
|
||||||
void toLower();
|
|
||||||
void toUpper();
|
void toUpper();
|
||||||
|
void toLower();
|
||||||
|
void toCaseFolded();
|
||||||
void rightJustified();
|
void rightJustified();
|
||||||
void leftJustified();
|
void leftJustified();
|
||||||
void mid();
|
void mid();
|
||||||
@ -1565,14 +1566,28 @@ void tst_QString::toUpper()
|
|||||||
|
|
||||||
QCOMPARE( QString(1, QChar(0xdf)).toUpper(), QString("SS"));
|
QCOMPARE( QString(1, QChar(0xdf)).toUpper(), QString("SS"));
|
||||||
|
|
||||||
QString lower;
|
QString lower, upper;
|
||||||
lower += QChar(QChar::highSurrogate(0x10428));
|
lower += QChar(QChar::highSurrogate(0x10428));
|
||||||
lower += QChar(QChar::lowSurrogate(0x10428));
|
lower += QChar(QChar::lowSurrogate(0x10428));
|
||||||
QString upper;
|
|
||||||
upper += QChar(QChar::highSurrogate(0x10400));
|
upper += QChar(QChar::highSurrogate(0x10400));
|
||||||
upper += QChar(QChar::lowSurrogate(0x10400));
|
upper += QChar(QChar::lowSurrogate(0x10400));
|
||||||
QCOMPARE( lower.toUpper(), upper);
|
QCOMPARE( lower.toUpper(), upper);
|
||||||
|
lower += lower;
|
||||||
|
upper += upper;
|
||||||
|
QCOMPARE( lower.toUpper(), upper);
|
||||||
|
|
||||||
|
// test for broken surrogate pair handling (low low hi low hi low)
|
||||||
|
lower.prepend(QChar(QChar::lowSurrogate(0x10428)));
|
||||||
|
lower.prepend(QChar(QChar::lowSurrogate(0x10428)));
|
||||||
|
upper.prepend(QChar(QChar::lowSurrogate(0x10428)));
|
||||||
|
upper.prepend(QChar(QChar::lowSurrogate(0x10428)));
|
||||||
|
QCOMPARE(lower.toUpper(), upper);
|
||||||
|
// test for broken surrogate pair handling (low low hi low hi low hi hi)
|
||||||
|
lower += QChar(QChar::highSurrogate(0x10428));
|
||||||
|
lower += QChar(QChar::highSurrogate(0x10428));
|
||||||
|
upper += QChar(QChar::highSurrogate(0x10428));
|
||||||
|
upper += QChar(QChar::highSurrogate(0x10428));
|
||||||
|
QCOMPARE(lower.toUpper(), upper);
|
||||||
|
|
||||||
#ifdef QT_USE_ICU
|
#ifdef QT_USE_ICU
|
||||||
// test doesn't work with ICU support, since QChar is unaware of any locale
|
// test doesn't work with ICU support, since QChar is unaware of any locale
|
||||||
@ -1610,13 +1625,28 @@ void tst_QString::toLower()
|
|||||||
|
|
||||||
QCOMPARE( QString(1, QChar(0x130)).toLower(), QString(QString(1, QChar(0x69)) + QChar(0x307)));
|
QCOMPARE( QString(1, QChar(0x130)).toLower(), QString(QString(1, QChar(0x69)) + QChar(0x307)));
|
||||||
|
|
||||||
QString lower;
|
QString lower, upper;
|
||||||
lower += QChar(QChar::highSurrogate(0x10428));
|
lower += QChar(QChar::highSurrogate(0x10428));
|
||||||
lower += QChar(QChar::lowSurrogate(0x10428));
|
lower += QChar(QChar::lowSurrogate(0x10428));
|
||||||
QString upper;
|
|
||||||
upper += QChar(QChar::highSurrogate(0x10400));
|
upper += QChar(QChar::highSurrogate(0x10400));
|
||||||
upper += QChar(QChar::lowSurrogate(0x10400));
|
upper += QChar(QChar::lowSurrogate(0x10400));
|
||||||
QCOMPARE( upper.toLower(), lower);
|
QCOMPARE( upper.toLower(), lower);
|
||||||
|
lower += lower;
|
||||||
|
upper += upper;
|
||||||
|
QCOMPARE( upper.toLower(), lower);
|
||||||
|
|
||||||
|
// test for broken surrogate pair handling (low low hi low hi low)
|
||||||
|
lower.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
lower.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
upper.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
upper.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
QCOMPARE( upper.toLower(), lower);
|
||||||
|
// test for broken surrogate pair handling (low low hi low hi low hi hi)
|
||||||
|
lower += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
lower += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
upper += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
upper += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
QCOMPARE( upper.toLower(), lower);
|
||||||
|
|
||||||
#ifdef QT_USE_ICU
|
#ifdef QT_USE_ICU
|
||||||
// test doesn't work with ICU support, since QChar is unaware of any locale
|
// test doesn't work with ICU support, since QChar is unaware of any locale
|
||||||
@ -1633,6 +1663,58 @@ void tst_QString::toLower()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QString::toCaseFolded()
|
||||||
|
{
|
||||||
|
QCOMPARE( QString().toCaseFolded(), QString() );
|
||||||
|
QCOMPARE( QString("").toCaseFolded(), QString("") );
|
||||||
|
QCOMPARE( QString("text").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("Text").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("tExt").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("teXt").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("texT").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("TExt").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("teXT").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("tEXt").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("tExT").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("TEXT").toCaseFolded(), QString("text") );
|
||||||
|
QCOMPARE( QString("@ABYZ[").toCaseFolded(), QString("@abyz["));
|
||||||
|
QCOMPARE( QString("@abyz[").toCaseFolded(), QString("@abyz["));
|
||||||
|
QCOMPARE( QString("`ABYZ{").toCaseFolded(), QString("`abyz{"));
|
||||||
|
QCOMPARE( QString("`abyz{").toCaseFolded(), QString("`abyz{"));
|
||||||
|
|
||||||
|
QString lower, upper;
|
||||||
|
upper += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
upper += QChar(QChar::lowSurrogate(0x10400));
|
||||||
|
lower += QChar(QChar::highSurrogate(0x10428));
|
||||||
|
lower += QChar(QChar::lowSurrogate(0x10428));
|
||||||
|
QCOMPARE( upper.toCaseFolded(), lower);
|
||||||
|
lower += lower;
|
||||||
|
upper += upper;
|
||||||
|
QCOMPARE( upper.toCaseFolded(), lower);
|
||||||
|
|
||||||
|
// test for broken surrogate pair handling (low low hi low hi low)
|
||||||
|
lower.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
lower.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
upper.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
upper.prepend(QChar(QChar::lowSurrogate(0x10400)));
|
||||||
|
QCOMPARE(upper.toCaseFolded(), lower);
|
||||||
|
// test for broken surrogate pair handling (low low hi low hi low hi hi)
|
||||||
|
lower += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
lower += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
upper += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
upper += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
QCOMPARE(upper.toCaseFolded(), lower);
|
||||||
|
|
||||||
|
//### we currently don't support full case foldings
|
||||||
|
for (int i = 0; i < 65536; ++i) {
|
||||||
|
QString str(1, QChar(i));
|
||||||
|
QString lower = str.toCaseFolded();
|
||||||
|
QVERIFY(lower.length() >= 1);
|
||||||
|
if (lower.length() == 1)
|
||||||
|
QVERIFY(str.toCaseFolded() == QString(1, QChar(i).toCaseFolded()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QString::trimmed()
|
void tst_QString::trimmed()
|
||||||
{
|
{
|
||||||
QString a;
|
QString a;
|
||||||
|
@ -75,6 +75,13 @@ private slots:
|
|||||||
void fromLatin1Alternatives() const;
|
void fromLatin1Alternatives() const;
|
||||||
void fromUtf8Alternatives_data() const;
|
void fromUtf8Alternatives_data() const;
|
||||||
void fromUtf8Alternatives() const;
|
void fromUtf8Alternatives() const;
|
||||||
|
|
||||||
|
void toUpper_data();
|
||||||
|
void toUpper();
|
||||||
|
void toLower_data();
|
||||||
|
void toLower();
|
||||||
|
void toCaseFolded_data();
|
||||||
|
void toCaseFolded();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QString::equals() const
|
void tst_QString::equals() const
|
||||||
@ -2601,6 +2608,89 @@ void tst_QString::fromUtf8Alternatives() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QString)
|
void tst_QString::toUpper_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("s");
|
||||||
|
|
||||||
|
QString lowerLatin1(300, QChar('a'));
|
||||||
|
QString upperLatin1(300, QChar('A'));
|
||||||
|
|
||||||
|
QString lowerDeseret;
|
||||||
|
{
|
||||||
|
QString pattern;
|
||||||
|
pattern += QChar(QChar::highSurrogate(0x10428));
|
||||||
|
pattern += QChar(QChar::lowSurrogate(0x10428));
|
||||||
|
for (int i = 0; i < 300 / pattern.size(); ++i)
|
||||||
|
lowerDeseret += pattern;
|
||||||
|
}
|
||||||
|
QString upperDeseret;
|
||||||
|
{
|
||||||
|
QString pattern;
|
||||||
|
pattern += QChar(QChar::highSurrogate(0x10400));
|
||||||
|
pattern += QChar(QChar::lowSurrogate(0x10400));
|
||||||
|
for (int i = 0; i < 300 / pattern.size(); ++i)
|
||||||
|
upperDeseret += pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString lowerLigature(600, QChar(0xFB03));
|
||||||
|
|
||||||
|
QTest::newRow("600<a>") << (lowerLatin1 + lowerLatin1);
|
||||||
|
QTest::newRow("600<A>") << (upperLatin1 + upperLatin1);
|
||||||
|
|
||||||
|
QTest::newRow("300<a>+300<A>") << (lowerLatin1 + upperLatin1);
|
||||||
|
QTest::newRow("300<A>+300<a>") << (upperLatin1 + lowerLatin1);
|
||||||
|
|
||||||
|
QTest::newRow("300<10428>") << (lowerDeseret + lowerDeseret);
|
||||||
|
QTest::newRow("300<10400>") << (upperDeseret + upperDeseret);
|
||||||
|
|
||||||
|
QTest::newRow("150<10428>+150<10400>") << (lowerDeseret + upperDeseret);
|
||||||
|
QTest::newRow("150<10400>+150<10428>") << (upperDeseret + lowerDeseret);
|
||||||
|
|
||||||
|
QTest::newRow("300a+150<10400>") << (lowerLatin1 + upperDeseret);
|
||||||
|
QTest::newRow("300a+150<10428>") << (lowerLatin1 + lowerDeseret);
|
||||||
|
QTest::newRow("300A+150<10400>") << (upperLatin1 + upperDeseret);
|
||||||
|
QTest::newRow("300A+150<10428>") << (upperLatin1 + lowerDeseret);
|
||||||
|
|
||||||
|
QTest::newRow("600<FB03> (ligature)") << lowerLigature;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QString::toUpper()
|
||||||
|
{
|
||||||
|
QFETCH(QString, s);
|
||||||
|
|
||||||
|
QBENCHMARK {
|
||||||
|
s.toUpper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QString::toLower_data()
|
||||||
|
{
|
||||||
|
toUpper_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QString::toLower()
|
||||||
|
{
|
||||||
|
QFETCH(QString, s);
|
||||||
|
|
||||||
|
QBENCHMARK {
|
||||||
|
s.toLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QString::toCaseFolded_data()
|
||||||
|
{
|
||||||
|
toUpper_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QString::toCaseFolded()
|
||||||
|
{
|
||||||
|
QFETCH(QString, s);
|
||||||
|
|
||||||
|
QBENCHMARK {
|
||||||
|
s.toCaseFolded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_APPLESS_MAIN(tst_QString)
|
||||||
|
|
||||||
#include "main.moc"
|
#include "main.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user