summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstring
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2011-05-15 23:09:31 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2011-05-15 23:09:31 (GMT)
commit5aa1cbcdacd19b2e526e358eddac1b7d55a994b5 (patch)
tree4aba78405e3d98081662fcb934f673acd1b79d42 /tests/auto/qstring
parent8592bcc80b7ec245b485fa54f8bd41c4484e93e0 (diff)
parent7e4a9187bb11b794e45d95d2e9fae026d6b0d07d (diff)
downloadQt-5aa1cbcdacd19b2e526e358eddac1b7d55a994b5.zip
Qt-5aa1cbcdacd19b2e526e358eddac1b7d55a994b5.tar.gz
Qt-5aa1cbcdacd19b2e526e358eddac1b7d55a994b5.tar.bz2
Merge remote branch 'origin/4.8' into qa-review-master
Conflicts: tests/auto/qaccessibility/tst_qaccessibility.cpp tests/auto/qsslsocket/tst_qsslsocket.cpp
Diffstat (limited to 'tests/auto/qstring')
-rw-r--r--tests/auto/qstring/qstring.pro2
-rw-r--r--tests/auto/qstring/tst_qstring.cpp93
2 files changed, 76 insertions, 19 deletions
diff --git a/tests/auto/qstring/qstring.pro b/tests/auto/qstring/qstring.pro
index e980042..1c123ad 100644
--- a/tests/auto/qstring/qstring.pro
+++ b/tests/auto/qstring/qstring.pro
@@ -7,3 +7,5 @@ QT = core
DEFINES += QT_NO_CAST_TO_ASCII
CONFIG += parallel_test
+
+contains(QT_CONFIG,icu):DEFINES += QT_USE_ICU
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index ad7515b..37a899c 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -222,6 +222,8 @@ private slots:
void task262677remove();
void QTBUG10404_compareRef();
void QTBUG9281_arg_locale();
+
+ void toUpperLower_icu();
};
typedef QList<int> IntList;
@@ -697,11 +699,11 @@ void tst_QString::acc_01()
QVERIFY(a<=c);
QVERIFY(!(c<=a));
QVERIFY(!(d<=a));
- QCOMPARE(a+b,(QString)"ABCABC");
- QCOMPARE(a +"XXXX",(QString)"ABCXXXX");
- QCOMPARE(a+'X',(QString)"ABCX");
- QCOMPARE("XXXX"+a,(QString)"XXXXABC");
- QCOMPARE('X'+a,(QString)"XABC");
+ QCOMPARE(QString(a+b),(QString)"ABCABC");
+ QCOMPARE(QString(a+"XXXX"),(QString)"ABCXXXX");
+ QCOMPARE(QString(a+'X'),(QString)"ABCX");
+ QCOMPARE(QString("XXXX"+a),(QString)"XXXXABC");
+ QCOMPARE(QString('X'+a),(QString)"XABC");
a = (const char*)0;
QVERIFY(a.isNull());
QVERIFY(*a.toLatin1().constData() == '\0');
@@ -1060,12 +1062,12 @@ void tst_QString::indexOf_data()
QString veryBigHaystack(500, 'a');
veryBigHaystack += 'B';
QTest::newRow("BoyerMooreStressTest") << veryBigHaystack << veryBigHaystack << 0 << true << 0;
- QTest::newRow("BoyerMooreStressTest2") << veryBigHaystack + 'c' << veryBigHaystack << 0 << true << 0;
- QTest::newRow("BoyerMooreStressTest3") << 'c' + veryBigHaystack << veryBigHaystack << 0 << true << 1;
- QTest::newRow("BoyerMooreStressTest4") << veryBigHaystack << veryBigHaystack + 'c' << 0 << true << -1;
- QTest::newRow("BoyerMooreStressTest5") << veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1;
- QTest::newRow("BoyerMooreStressTest6") << 'd' + veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1;
- QTest::newRow("BoyerMooreStressTest6") << veryBigHaystack + 'c' << 'c' + veryBigHaystack << 0 << true << -1;
+ QTest::newRow("BoyerMooreStressTest2") << QString(veryBigHaystack + 'c') << veryBigHaystack << 0 << true << 0;
+ QTest::newRow("BoyerMooreStressTest3") << QString('c' + veryBigHaystack) << veryBigHaystack << 0 << true << 1;
+ QTest::newRow("BoyerMooreStressTest4") << veryBigHaystack << QString(veryBigHaystack + 'c') << 0 << true << -1;
+ QTest::newRow("BoyerMooreStressTest5") << veryBigHaystack << QString('c' + veryBigHaystack) << 0 << true << -1;
+ QTest::newRow("BoyerMooreStressTest6") << QString('d' + veryBigHaystack) << QString('c' + veryBigHaystack) << 0 << true << -1;
+ QTest::newRow("BoyerMooreStressTest6") << QString(veryBigHaystack + 'c') << QString('c' + veryBigHaystack) << 0 << true << -1;
QTest::newRow("BoyerMooreInsensitiveStressTest") << veryBigHaystack << veryBigHaystack << 0 << false << 0;
@@ -1175,14 +1177,14 @@ void tst_QString::indexOf2_data()
QString whale = "a5zby6cx7dw8evf9ug0th1si2rj3qkp4lomn";
QString minnow = "zby";
QTest::newRow( "data40" ) << whale << minnow << 2;
- QTest::newRow( "data41" ) << (whale + whale) << minnow << 2;
- QTest::newRow( "data42" ) << (minnow + whale) << minnow << 0;
+ QTest::newRow( "data41" ) << QString(whale + whale) << minnow << 2;
+ QTest::newRow( "data42" ) << QString(minnow + whale) << minnow << 0;
QTest::newRow( "data43" ) << whale << whale << 0;
- QTest::newRow( "data44" ) << (whale + whale) << whale << 0;
- QTest::newRow( "data45" ) << whale << (whale + whale) << -1;
- QTest::newRow( "data46" ) << (whale + whale) << (whale + whale) << 0;
- QTest::newRow( "data47" ) << (whale + whale) << (whale + minnow) << -1;
- QTest::newRow( "data48" ) << (minnow + whale) << whale << (int)minnow.length();
+ QTest::newRow( "data44" ) << QString(whale + whale) << whale << 0;
+ QTest::newRow( "data45" ) << whale << QString(whale + whale) << -1;
+ QTest::newRow( "data46" ) << QString(whale + whale) << QString(whale + whale) << 0;
+ QTest::newRow( "data47" ) << QString(whale + whale) << QString(whale + minnow) << -1;
+ QTest::newRow( "data48" ) << QString(minnow + whale) << whale << (int)minnow.length();
}
void tst_QString::indexOf2()
@@ -1603,6 +1605,11 @@ void tst_QString::toUpper()
QCOMPARE( lower.toUpper(), upper);
+#ifdef QT_USE_ICU
+ // test doesn't work with ICU support, since QChar is unaware of any locale
+ QEXPECT_FAIL("", "test doesn't work with ICU support, since QChar is unaware of any locale", Continue);
+ QVERIFY(false);
+#else
for (int i = 0; i < 65536; ++i) {
QString str(1, QChar(i));
QString upper = str.toUpper();
@@ -1610,6 +1617,7 @@ void tst_QString::toUpper()
if (upper.length() == 1)
QVERIFY(upper == QString(1, QChar(i).toUpper()));
}
+#endif
}
void tst_QString::toLower()
@@ -1631,7 +1639,7 @@ void tst_QString::toLower()
QCOMPARE( QString("`ABYZ{").toLower(), QString("`abyz{"));
QCOMPARE( QString("`abyz{").toLower(), QString("`abyz{"));
- QCOMPARE( QString(1, QChar(0x130)).toLower(), QString(1, QChar(0x69)) + QChar(0x307));
+ QCOMPARE( QString(1, QChar(0x130)).toLower(), QString(QString(1, QChar(0x69)) + QChar(0x307)));
QString lower;
lower += QChar(QChar::highSurrogate(0x10428));
@@ -1641,6 +1649,11 @@ void tst_QString::toLower()
upper += QChar(QChar::lowSurrogate(0x10400));
QCOMPARE( upper.toLower(), lower);
+#ifdef QT_USE_ICU
+ // test doesn't work with ICU support, since QChar is unaware of any locale
+ QEXPECT_FAIL("", "test doesn't work with ICU support, since QChar is unaware of any locale", Continue);
+ QVERIFY(false);
+#else
for (int i = 0; i < 65536; ++i) {
QString str(1, QChar(i));
QString lower = str.toLower();
@@ -1648,6 +1661,7 @@ void tst_QString::toLower()
if (lower.length() == 1)
QVERIFY(str.toLower() == QString(1, QChar(i).toLower()));
}
+#endif
}
void tst_QString::trimmed()
@@ -4352,6 +4366,8 @@ void tst_QString::localeAwareCompare()
#elif defined (Q_WS_MAC)
QSKIP("Setting the locale is not supported on OS X (you can set the C locale, but that won't affect CFStringCompare which is used to compare strings)", SkipAll);
+#elif defined(QT_USE_ICU)
+ QLocale::setDefault(QLocale(locale));
#else
if (!locale.isEmpty()) {
const char *newLocale = setlocale(LC_ALL, locale.toLatin1());
@@ -4363,6 +4379,11 @@ void tst_QString::localeAwareCompare()
}
#endif
+#ifdef QT_USE_ICU
+ // ### for c1, ICU disagrees with libc on how to compare
+ QEXPECT_FAIL("c1", "ICU disagrees with test", Abort);
+#endif
+
int testres = QString::localeAwareCompare(s1, s2);
if (result < 0) {
QVERIFY(testres < 0);
@@ -5065,6 +5086,40 @@ void tst_QString::QTBUG9281_arg_locale()
QLocale::setDefault(QLocale::C);
}
+void tst_QString::toUpperLower_icu()
+{
+#ifndef QT_USE_ICU
+ QSKIP("Qt was built without ICU support", SkipAll);
+#endif
+
+ QString s = QString::fromLatin1("i");
+
+ QCOMPARE(s.toUpper(), QString::fromLatin1("I"));
+ QCOMPARE(s.toLower(), QString::fromLatin1("i"));
+
+ QLocale::setDefault(QLocale(QLocale::Turkish, QLocale::Turkey));
+
+ // turkish locale has a capital I with a dot (U+0130, utf8 c4b0)
+
+ QCOMPARE(s.toUpper(), QString::fromUtf8("\xc4\xb0"));
+ QCOMPARE(QString::fromUtf8("\xc4\xb0").toLower(), s);
+
+ // nothing should happen here
+ QCOMPARE(s.toLower(), s);
+ QCOMPARE(QString::fromLatin1("I").toUpper(), QString::fromLatin1("I"));
+
+ // U+0131, utf8 c4b1 is the lower-case i without a dot
+ QString sup = QString::fromUtf8("\xc4\xb1");
+
+ QCOMPARE(sup.toUpper(), QString::fromLatin1("I"));
+ QCOMPARE(QString::fromLatin1("I").toLower(), sup);
+
+ // nothing should happen here
+ QCOMPARE(sup.toLower(), sup);
+ QCOMPARE(QString::fromLatin1("i").toLower(), QString::fromLatin1("i"));
+
+ // the cleanup function will restore the default locale
+}
QTEST_APPLESS_MAIN(tst_QString)