diff options
Diffstat (limited to 'tests/auto/corelib/tools/qstring/tst_qstring.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 107 |
1 files changed, 105 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 8e30a66d6f..aa61885a47 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -195,6 +195,8 @@ private slots: void stringRef_local8Bit(); void fromLatin1(); void fromAscii(); + void fromUcs4(); + void toUcs4(); void arg(); void number(); void arg_fillChar_data(); @@ -238,7 +240,7 @@ private slots: #ifdef QT_USE_ICU void toUpperLower_icu(); #endif -#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) +#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA) void literals(); #endif void eightBitLiterals_data(); @@ -1003,10 +1005,12 @@ void tst_QString::sprintf() a.sprintf("%s%n%s", "hello", &n1, "goodbye"); QCOMPARE(n1, 5); QCOMPARE(a, QString("hellogoodbye")); +#ifndef Q_CC_MINGW // does not know %ll qlonglong n2; a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz"); QCOMPARE((int)n2, 6); QCOMPARE(a, QString("foobarwhiz")); +#endif } /* @@ -1425,6 +1429,55 @@ void tst_QString::contains() QVERIFY(a.contains(QRegularExpression("[FG][HI]"))); QVERIFY(a.contains(QRegularExpression("[G][HE]"))); + { + QRegularExpressionMatch match; + QVERIFY(!match.hasMatch()); + + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[G][HE]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[FG]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 15); + QCOMPARE(match.captured(), QString("fGEFG")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 14); + QCOMPARE(match.captured(1), QStringLiteral("GEF")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[F]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QString("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + QVERIFY(!a.contains(QRegularExpression("ZZZ"), &match)); + // doesn't match, but ensure match didn't change + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QStringLiteral("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + // don't crash with a null pointer + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), 0)); + QVERIFY(!a.contains(QRegularExpression("ZZZ"), 0)); + } + CREATE_REF(QLatin1String("FG")); QVERIFY(a.contains(ref)); QVERIFY(a.contains(ref, Qt::CaseInsensitive)); @@ -3880,6 +3933,52 @@ void tst_QString::fromAscii() QVERIFY(a.size() == 5); } +void tst_QString::fromUcs4() +{ + QString s; + s = QString::fromUcs4( 0 ); + QVERIFY( s.isNull() ); + QCOMPARE( s.size(), 0 ); + s = QString::fromUcs4( 0, 0 ); + QVERIFY( s.isNull() ); + QCOMPARE( s.size(), 0 ); + s = QString::fromUcs4( 0, 5 ); + QVERIFY( s.isNull() ); + QCOMPARE( s.size(), 0 ); + + uint nil = '\0'; + s = QString::fromUcs4( &nil ); + QVERIFY( !s.isNull() ); + QCOMPARE( s.size(), 0 ); + s = QString::fromUcs4( &nil, 0 ); + QVERIFY( !s.isNull() ); + QCOMPARE( s.size(), 0 ); + + uint bmp = 'a'; + s = QString::fromUcs4( &bmp, 1 ); + QVERIFY( !s.isNull() ); + QCOMPARE( s.size(), 1 ); + + uint smp = 0x10000; + s = QString::fromUcs4( &smp, 1 ); + QVERIFY( !s.isNull() ); + QCOMPARE( s.size(), 2 ); +} + +void tst_QString::toUcs4() +{ + QString s; + QCOMPARE( s.toUcs4().size(), 0 ); + + QChar bmp = QLatin1Char('a'); + s = QString(&bmp, 1); + QCOMPARE( s.toUcs4().size(), 1 ); + + QChar smp[] = { QChar::highSurrogate(0x10000), QChar::lowSurrogate(0x10000) }; + s = QString(smp, 2); + QCOMPARE( s.toUcs4().size(), 1 ); +} + void tst_QString::arg() { /* @@ -5187,6 +5286,9 @@ void tst_QString::QCharRefDetaching() const void tst_QString::sprintfZU() const { +#ifdef Q_CC_MINGW + QSKIP("MinGW does not support '%zu'."); +#else { QString string; size_t s = 6; @@ -5215,6 +5317,7 @@ void tst_QString::sprintfZU() const string.sprintf("%zu %s\n", s, "foo"); QCOMPARE(string, QString::fromLatin1("6 foo\n")); } +#endif // !Q_CC_MINGW } void tst_QString::repeatedSignature() const @@ -5382,7 +5485,7 @@ void tst_QString::toUpperLower_icu() } #endif -#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) +#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA) // Only tested on c++0x compliant compiler or gcc void tst_QString::literals() { |